3 use Test
::More no_plan
;
6 use MooseX
::TimestampTZ
;
8 # In this test script, a node joins a swarm that has a more up-to-date
9 # reference list than the one it got from the tracker, and updates its
10 # reference list from a peer.
13 use_ok
('t::TestUtils');
16 use_ok
('Coro::Event');
17 use_ok
('VCS::Git::Torrent');
18 use_ok
('VCS::Git::Torrent::Peer::Async');
19 use_ok
('VCS::Git::Torrent::PWP', qw(:pwp_constants));
20 use_ok
('VCS::Git::Torrent::Reference');
23 my $path = mk_tmp_repo
();
24 my $git = Git
->repository($path);
25 ok
($git, 'git repo created');
27 my $t = VCS
::Git
::Torrent
->new(
28 repo_hash
=> '501d' x
10,
31 ok
($t, 'gittorrent created');
33 qx(echo foo
>> $path/bar
);
34 $git->command('add', 'bar');
35 $git->command('commit', '-a', '-m baz');
36 my $sha1 = $git->command_oneline('show-ref', '-s', 'master');
37 like
($sha1, qr/[[:xdigit:]]{40}/, 'object inserted successfully');
39 my $ref = VCS
::Git
::Torrent
::Reference
->new(
41 tagged_object
=> $sha1,
42 refs
=> { 'HEAD' => $sha1 },
43 tagger
=> 'Elanour Rigby <nowhereman@example.com>',
44 tagdate
=> timestamptz
,
45 comment
=> "Ah, look at all the lonely people\n",
47 ok
($ref, 'Reference created');
49 $t->references([$ref]);
51 my ($port_1, $port_2) = @
{ random_port_pair
() };
53 my $peer_1 = VCS
::Git
::Torrent
::Peer
::Async
->new(
56 peer_id
=> 'AlphaPeer1AlphaPeer1',
58 ok
($peer_1, 'Peer created');
60 my $path2 = mk_tmp_repo
();
61 my $git2 = Git
->repository($path2);
62 my $t2 = VCS
::Git
::Torrent
->new(
63 repo_hash
=> '501d' x
10,
67 my $peer_2 = VCS
::Git
::Torrent
::Peer
::Async
->new(
70 peer_id
=> 'BravoPeer2BravoPeer2',
72 ok
($peer_2, 'Another peer created');
74 $peer_1->connect("localhost:$port_2");
76 # let the connect get processed
79 my $victim = $peer_2->connections->[0]->remote;
80 $peer_2->send_message($victim, GTP_PWP_REFERENCES
);
87 is
(scalar(@
{ $peer_2->references }), 1, 'we received a reference from our peer');
89 for my $attr ( qw(tag_id tagged_object tagger tagdate comment refs) ) {
91 $peer_2->references->[0]->$attr,
93 'reconstructed Reference: ' . $attr . ' matches'