X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=t%2FGearman.t;h=8e211b4d8f470146d3e7022aaee8d4f993e46b7b;hb=fc1eb90c6c31458133e46ab167b0e9187f5e3771;hp=9c0329606b2ce5a6b0a436c8ca3279ffba3d2acc;hpb=3ace20da7d7b537fea9911ca8e1d70135ba44bcc;p=cloudstore.git diff --git a/t/Gearman.t b/t/Gearman.t index 9c03296..8e211b4 100755 --- a/t/Gearman.t +++ b/t/Gearman.t @@ -2,7 +2,7 @@ use strict; use warnings; -use Test::More tests => 15; +use Test::More tests => 43; use Data::Dump qw(dump); use lib 'lib'; @@ -16,11 +16,29 @@ my $user = $ARGV[0] || 2001; sub gearman { my ( $function, $args ) = @_; - ok my $o = CloudStore::Gearman->gearman_do( @_ ), $_[0]; - diag dump $o; + ok( my $o = CloudStore::Gearman->gearman_do( @_ ), join(' ',@_) ); + diag "result = ",dump $o if $ENV{DEBUG}; return $o; } +sub file_exists($) { + my ( $file ) = @_; + CloudStore::Gearman->gearman_do( file_size => $file ); +} + +sub test_refresh_file_list { + my ( $login ) = @_; + ok ! file_exists( "~$login/.meta/files" ), "refresh_file_list removed .meta/files"; + gearman list_files => "~$login"; +} + +my $u1 = gearman 'create_user' => 'test@example.com secret 0'; +like $u1, qr/u\d+/, "login $u1"; +my $u2 = gearman 'create_user' => 'test2@example.com secret 0'; +like $u2, qr/u\d+/, "login $u2"; +my $u3 = gearman 'create_user' => 'slice2@example.com secret 0'; +like $u3, qr/u\d+/, "login $u2 (on other slice)"; + my $o = gearman $hostname . '_s1_quota_get' => $user; diag dump $o; cmp_ok $o, '=~', qr/^(\d+)\s+(\d+)$/, 'format: used quota'; @@ -29,21 +47,41 @@ gearman( 'user_usage' => $user ); gearman( $hostname . '_s1_torrent_list' ); +diag "create .meta/files if it doesn't exist"; +foreach my $login ( $u1, $u2 ) { + gearman list_files => "~$login"; + ok file_exists "~$login/.meta/files", "file_exists ~$login/.meta/files"; +} + +file_exists "~$u1/foo.txt" || BAIL_OUT("~$u1/foo.txt is required for rest of tests"); -gearman send_file => '~u2001/foo.txt#~u2002/dir with space/file with space'; +gearman send_file => "~$u1/foo.txt#~$u2/dir with space/file with space"; +test_refresh_file_list "$u2"; -gearman delete => '~u2002/dir with space/file with space'; +gearman delete => "~$u2/dir with space/file with space"; +test_refresh_file_list "$u2"; -gearman send_file => '~u2001/foo.txt#~u2002/foo.txt'; +gearman send_file => "~$u1/foo.txt#~$u2/foo.txt"; +test_refresh_file_list "$u2"; -gearman rename_file => '~u2002/foo.txt#bar.txt'; -gearman rename_file => '~u2002/bar.txt#baz.txt'; +gearman rename_file => "~$u2/foo.txt#bar.txt"; +test_refresh_file_list "$u2"; +gearman rename_file => "~$u2/bar.txt#baz.txt"; +test_refresh_file_list "$u2"; cmp_ok -gearman( file_size => '~u2001/foo.txt' ), '==', -gearman( file_size => '~u2002/baz.txt' ), 'size_same'; +gearman( file_size => "~$u1/foo.txt" ), '==', +gearman( file_size => "~$u2/baz.txt" ), 'size_same'; + +diag "test symlink to other shard"; +gearman send_file => "~$u1/foo.txt#~$u3/foo.txt"; +cmp_ok +gearman( file_size => "~$u1/foo.txt" ), '==', +gearman( file_size => "~$u3/foo.txt" ), 'cross-slice symlink size same'; +test_refresh_file_list "$u3"; -gearman delete => '~u2002/baz.txt'; +gearman delete => "~$u2/baz.txt"; +test_refresh_file_list "$u2"; -ok ! CloudStore::Gearman->gearman_do( file_size => '~u2002/baz.txt' ), 'deleted file size'; +ok ! file_exists "~$u2/baz.txt", 'deleted file size';