Skip to content

Commit

Permalink
Fixing multi-threaded test errors
Browse files Browse the repository at this point in the history
  • Loading branch information
phochste committed Jan 30, 2018
1 parent 75089aa commit 452eddd
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 58 deletions.
11 changes: 8 additions & 3 deletions t/Catmandu-Cmd-stream.t
Expand Up @@ -6,6 +6,7 @@ use Test::More;
use Test::Exception;
use App::Cmd::Tester::CaptureExternal;
use Cpanel::JSON::XS;
use Path::Tiny;
use utf8;

my $pkg;
Expand All @@ -18,6 +19,8 @@ require_ok $pkg;

use Catmandu::CLI;

path("t/tmp/cmd-stream")->mkpath;

note("download");
{
my $result = test_app(
Expand All @@ -35,17 +38,19 @@ note("upload");
{
my $result = test_app(
qq|Catmandu::CLI| => [
qw(stream cpanfile to File::Simple --root t/data --keysize 9 --bag 456 --id test.txt)
qw(stream cpanfile to File::Simple --root t/tmp/cmd-stream --keysize 9 --bag 456 --id test.txt)
]
);

ok !$result->stdout;

is $result->error, undef, 'threw no exceptions';

ok -f "t/data/000/000/456/test.txt", "found the correct file";
ok -f "t/tmp/cmd-stream/000/000/456/test.txt", "found the correct file";

unlink "t/data/000/000/456/test.txt";
unlink "t/tmp/cmd-stream/000/000/456/test.txt";
}

path("t/tmp/cmd-stream")->remove_tree;

done_testing;
40 changes: 22 additions & 18 deletions t/Catmandu-Plugin-SideCar.t
Expand Up @@ -5,6 +5,7 @@ use warnings;
use Test::More;
use Test::Exception;
use Catmandu;
use Path::Tiny;
use utf8;

my $pkg;
Expand All @@ -15,11 +16,13 @@ BEGIN {
}
require_ok $pkg;

path("t/tmp/sidecar")->mkpath;

note("Combined Simple + Hash sidecar");
{
my $store = Catmandu->store(
'File::Simple',
root => 't/data3',
root => 't/tmp/sidecar',
keysize => 9,
bags => {
index =>
Expand All @@ -33,33 +36,33 @@ note("Combined Simple + Hash sidecar");
ok $index , 'got an index';

note("...exists");
ok !$index->exists('1234');
ok !$index->exists('9012');

note("...add");
ok $index->add({_id => 1234, foo => 'bar', test => [1, 2, 3]}),
'adding bag `1234`';
ok $index->add({_id => 9012, foo => 'bar', test => [1, 2, 3]}),
'adding bag `9012`';

ok -d "t/data3/000/001/234";
ok -d "t/tmp/sidecar/000/009/012";

note("...get");

my $item = $index->get('1234');
my $item = $index->get('9012');

ok $item;

is_deeply $item , {_id => 1234, foo => 'bar', test => [1, 2, 3]},
is_deeply $item , {_id => 9012, foo => 'bar', test => [1, 2, 3]},
'found combined metadata and file data';

note("...bag");
my $container = $store->bag('1234');
my $container = $store->bag('9012');

ok $container , 'got bag(1234)';
ok $container , 'got bag(9012)';

note("...upload");
ok $container->upload(IO::File->new('t/data2/000/000/001/test.txt'),
'test1.txt');

ok -f 't/data3/000/001/234/test1.txt', 'test1.txt exists (2)';
ok -f 't/tmp/sidecar/000/009/012/test1.txt', 'test1.txt exists (2)';

note("...list");
my $array = [sort @{$container->map(sub {shift->{_id}})->to_array}];
Expand Down Expand Up @@ -91,8 +94,7 @@ note("Combined Simple + Hash sidecar");

is_deeply $array , [], 'got correct response';

ok !-f 't/data/000/001/234/test1.txt', 'test1.txt doesnt exists (1)';
ok !-f 't/data3/000/001/234/test1.txt', 'test1.txt doesnt exists (2)';
ok !-f 't/tmp/sidecar/000/009/012/test1.txt', 'test1.txt doesnt exists (2)';

note("...delete_all (index)");
lives_ok {$index->delete_all()} 'delete_all';
Expand All @@ -111,7 +113,7 @@ note("Combined Hash + Simple sidecar");
plugins => [qw(SideCar)],
sidecar => {
package => "File::Simple",
options => {'root' => 't/data3', 'keysize' => 9,}
options => {'root' => 't/tmp/sidecar', 'keysize' => 9,}
},
sidecar_bag => 'index'
}
Expand All @@ -120,22 +122,22 @@ note("Combined Hash + Simple sidecar");

ok $store , 'got a store';

ok $store->bag->add({_id => '1234', name => 'patrick'}),
ok $store->bag->add({_id => '9012', name => 'patrick'}),
'adding a record';

note("...upload");
ok $store->bag->files('1234')
ok $store->bag->files('9012')
->upload(IO::File->new('t/data2/000/000/001/test.txt'), 'test1.txt');

ok -f 't/data3/000/001/234/test1.txt', 'test1.txt exists (2)';
ok -f 't/tmp/sidecar/000/009/012/test1.txt', 'test1.txt exists (2)';

note("...get");
my $file = $store->bag->files('1234')->get("test1.txt");
my $file = $store->bag->files('9012')->get("test1.txt");

ok $file;

note("...stream");
my $str = $store->bag->files('1234')->as_string_utf8($file);
my $str = $store->bag->files('9012')->as_string_utf8($file);

ok $str , 'can stream the data';

Expand All @@ -149,4 +151,6 @@ note("Combined Hash + Simple sidecar");
is_deeply $array , [], 'got correct response';
}

path("t/tmp/sidecar")->remove_tree;

done_testing;
6 changes: 3 additions & 3 deletions t/Catmandu-Store-File-Memory-Bag.t
Expand Up @@ -23,11 +23,11 @@ my $index = $store->bag;
ok $store , 'got a store';
ok $index , 'got an index';

ok $index->add({_id => 1234}), 'adding bag `1234`';
ok $index->add({_id => 8012}), 'adding bag `8012`';

my $bag = $store->bag('1234');
my $bag = $store->bag('8012');

ok $bag , 'got bag(1234)';
ok $bag , 'got bag(8012)';

note("add");
{
Expand Down
29 changes: 18 additions & 11 deletions t/Catmandu-Store-File-Multi-Bag.t
Expand Up @@ -5,6 +5,7 @@ use Test::More;
use Test::Exception;
use Catmandu::Store::File::Simple;
use Catmandu::Store::File::Multi;
use Path::Tiny;
use utf8;

my $pkg;
Expand All @@ -16,9 +17,12 @@ BEGIN {

require_ok $pkg;

path("t/tmp/multi-bag/a")->mkpath;
path("t/tmp/multi-bag/b")->mkpath;

my $stores = [
Catmandu::Store::File::Simple->new(root => 't/data', keysize => 9),
Catmandu::Store::File::Simple->new(root => 't/data3', keysize => 9),
Catmandu::Store::File::Simple->new(root => 't/tmp/multi-bag/a', keysize => 9),
Catmandu::Store::File::Simple->new(root => 't/tmp/multi-bag/b', keysize => 9),
];

my $store = Catmandu::Store::File::Multi->new(stores => $stores);
Expand All @@ -27,11 +31,11 @@ my $index = $store->index;
ok $store , 'got a store';
ok $index , 'got an index';

ok $index->add({_id => 1234}), 'adding bag `1234`';
ok $index->add({_id => 7012}), 'adding bag `7012`';

my $bag = $store->bag('1234');
my $bag = $store->bag('7012');

ok $bag , 'got bag(1234)';
ok $bag , 'got bag(7012)';

note("add");
{
Expand All @@ -42,9 +46,9 @@ note("add");

is $n1 , 16, '16 bytes';

ok -f 't/data/000/001/234/test1.txt', 'test1.txt exists';
ok -f 't/tmp/multi-bag/a/000/007/012/test1.txt', 'test1.txt exists';

ok -f 't/data3/000/001/234/test1.txt', 'test1.txt exists';
ok -f 't/tmp/multi-bag/b/000/007/012/test1.txt', 'test1.txt exists';

my $n2 = $bag->upload(IO::File->new('t/data2/000/000/002/test.txt'),
'test2.txt');
Expand All @@ -53,9 +57,9 @@ note("add");

is $n2 , 6, '6 bytes';

ok -f 't/data/000/001/234/test2.txt', 'test2.txt exists';
ok -f 't/tmp/multi-bag/a/000/007/012/test2.txt', 'test2.txt exists';

ok -f 't/data3/000/001/234/test2.txt', 'test1.txt exists';
ok -f 't/tmp/multi-bag/b/000/007/012/test2.txt', 'test1.txt exists';

my $n3 = $bag->upload(IO::File->new('t/data2/000/000/003/test.txt'),
'test3.txt');
Expand All @@ -64,9 +68,9 @@ note("add");

is $n3 , 6, '6 bytes';

ok -f 't/data/000/001/234/test3.txt', 'test3.txt exists';
ok -f 't/tmp/multi-bag/a/000/007/012/test3.txt', 'test3.txt exists';

ok -f 't/data3/000/001/234/test3.txt', 'test1.txt exists';
ok -f 't/tmp/multi-bag/b/000/007/012/test3.txt', 'test1.txt exists';

my $data = {
_id => 'test4.txt',
Expand Down Expand Up @@ -131,4 +135,7 @@ note("...delete_all (index)");
is_deeply $array , [], 'got correct response';
}

path("t/tmp/multi-bag/a")->remove_tree;
path("t/tmp/multi-bag/b")->remove_tree;

done_testing();
15 changes: 11 additions & 4 deletions t/Catmandu-Store-File-Multi-Index.t
Expand Up @@ -5,6 +5,7 @@ use Test::More;
use Test::Exception;
use Catmandu::Store::File::Simple;
use Catmandu::Store::File::Multi;
use Path::Tiny;

my $pkg;

Expand Down Expand Up @@ -57,9 +58,12 @@ note("get");
}
}

path("t/tmp/multi-index/a")->mkpath;
path("t/tmp/multi-index/b")->mkpath;

$stores = [
Catmandu::Store::File::Simple->new(root => 't/data', keysize => 9),
Catmandu::Store::File::Simple->new(root => 't/data3', keysize => 9),
Catmandu::Store::File::Simple->new(root => 't/tmp/multi-index/a', keysize => 9),
Catmandu::Store::File::Simple->new(root => 't/tmp/multi-index/b', keysize => 9),
];

$store = Catmandu::Store::File::Multi->new(stores => $stores);
Expand All @@ -78,19 +82,22 @@ note("add");

ok $c , 'add(1234)';

ok -d "t/data/000/001/234", 'found a container on disk';
ok -d "t/tmp/multi-index/a/000/001/234", 'found a container on disk';
}

note("delete");
{
ok $index->delete('1234'), 'delete(1234)';

ok !-d "t/data/000/001/234", 'container on disk was deleted';
ok !-d "t/tmp/multi-index/a/000/001/234", 'container on disk was deleted';
}

note("delete_all");
{
lives_ok {$index->delete_all()} 'delete_all';
}

path("t/tmp/multi-index/a")->remove_tree;
path("t/tmp/multi-index/b")->remove_tree;

done_testing();
31 changes: 19 additions & 12 deletions t/Catmandu-Store-File-Multi.t
Expand Up @@ -6,6 +6,7 @@ use Test::More;
use Test::Exception;
use Catmandu::Store::File::Simple;
use Catmandu::Store::Hash;
use Path::Tiny;
use utf8;

my $pkg;
Expand All @@ -16,11 +17,14 @@ BEGIN {
}
require_ok $pkg;

path("t/tmp/multi/a")->mkpath;
path("t/tmp/multi/b")->mkpath;

note("Simple stores");
{
my $stores = [
Catmandu::Store::File::Simple->new(root => 't/data', keysize => 9),
Catmandu::Store::File::Simple->new(root => 't/data3', keysize => 9),
Catmandu::Store::File::Simple->new(root => 't/tmp/multi/a', keysize => 9),
Catmandu::Store::File::Simple->new(root => 't/tmp/multi/b', keysize => 9),
];

my $store = $pkg->new(stores => $stores);
Expand All @@ -30,25 +34,25 @@ note("Simple stores");
ok $index , 'got an index';

note("...exists");
ok !$index->exists('1234');
ok !$index->exists('6012');

note("...add");
ok $index->add({_id => 1234}), 'adding bag `1234`';
ok $index->add({_id => 6012}), 'adding bag `6012`';

ok -d "t/data/000/001/234";
ok -d "t/data3/000/001/234";
ok -d "t/tmp/multi/a/000/006/012";
ok -d "t/tmp/multi/b/000/006/012";

note("...bag");
my $bag = $store->bag->files('1234');
my $bag = $store->bag->files('6012');

ok $bag , 'got bag(1234)';
ok $bag , 'got bag(6012)';

note("...upload");
ok $bag->upload(IO::File->new('t/data2/000/000/001/test.txt'),
'test1.txt');

ok -f 't/data/000/001/234/test1.txt', 'test1.txt exists (1)';
ok -f 't/data3/000/001/234/test1.txt', 'test1.txt exists (2)';
ok -f 't/tmp/multi/a/000/006/012/test1.txt', 'test1.txt exists (1)';
ok -f 't/tmp/multi/b/000/006/012/test1.txt', 'test1.txt exists (2)';

note("...list");
my $array = [sort @{$bag->map(sub {shift->{_id}})->to_array}];
Expand Down Expand Up @@ -80,8 +84,8 @@ note("Simple stores");

is_deeply $array , [], 'got correct response';

ok !-f 't/data/000/001/234/test1.txt', 'test1.txt doesnt exists (1)';
ok !-f 't/data3/000/001/234/test1.txt', 'test1.txt doesnt exists (2)';
ok !-f 't/tmp/multi/a/000/006/012/test1.txt', 'test1.txt doesnt exists (1)';
ok !-f 't/tmp/multi/b/000/006/012/test1.txt', 'test1.txt doesnt exists (2)';

note("...delete_all (index)");
lives_ok {$index->delete_all()} 'delete_all';
Expand All @@ -91,4 +95,7 @@ note("Simple stores");
is_deeply $array , [], 'got correct response';
}

path("t/tmp/multi/a")->remove_tree;
path("t/tmp/multi/b")->remove_tree;

done_testing;

0 comments on commit 452eddd

Please sign in to comment.