@@ -24,10 +24,12 @@ my $project = $db->resultset('Projects')->create({name => "tests", displayname =
2424my $jobset = createBaseJobset($db , " content-addressed" , " content-addressed.nix" , $ctx {jobsdir });
2525
2626ok(evalSucceeds($ctx {context }, $jobset ), " Evaluating jobs/content-addressed.nix should exit with return code 0" );
27- is(nrQueuedBuildsForJobset($jobset ), 10 , " Evaluating jobs/content-addressed.nix should result in 6 builds" );
27+ is(nrQueuedBuildsForJobset($jobset ), 14 , " Evaluating jobs/content-addressed.nix should result in 14 builds" );
2828
29- for my $build (queuedBuildsForJobset($jobset )) {
30- ok(runBuild($ctx {context }, $build ), " Build '" .$build -> job." ' from jobs/content-addressed.nix should exit with code 0" );
29+ my @builds = queuedBuildsForJobset($jobset );
30+ ok(runBuilds($ctx {context }, @builds ), " Building all jobs from jobs/content-addressed.nix should exit with code 0" );
31+
32+ for my $build (@builds ) {
3133 my $newbuild = $db -> resultset(' Builds' )-> find($build -> id);
3234 is($newbuild -> finished, 1, " Build '" .$build -> job." ' from jobs/content-addressed.nix should be finished." );
3335 my $expected = $build -> job eq " fails" ? 1 : $build -> job =~ / with_failed/ ? 6 : $build -> job =~ / FailingCA/ ? 2 : 0;
@@ -56,5 +58,46 @@ for my $build (queuedBuildsForJobset($jobset)) {
5658# XXX: This test seems to not do what it seems to be doing. See documentation: https://metacpan.org/pod/Test2::V0#isnt($got,-$do_not_want,-$name)
5759isnt(<$ctx {deststoredir }/realisations/*>, " " , " The destination store should have the realisations of the built derivations registered" );
5860
61+ # Early cutoff: earlyCutoffUpstream1 and earlyCutoffUpstream2 have
62+ # different derivations but produce the same content-addressed output.
63+ # After building earlyCutoffDownstream1, earlyCutoffDownstream2 should
64+ # be cached because its resolved input is identical.
65+ my $upstream1 = $db -> resultset(' Builds' )-> find({
66+ jobset_id => $jobset -> id,
67+ job => " earlyCutoffUpstream1" ,
68+ });
69+ my $upstream2 = $db -> resultset(' Builds' )-> find({
70+ jobset_id => $jobset -> id,
71+ job => " earlyCutoffUpstream2" ,
72+ });
73+
74+ my $upstream1_out = $upstream1 -> buildoutputs-> find({ name => " out" });
75+ my $upstream2_out = $upstream2 -> buildoutputs-> find({ name => " out" });
76+ is($upstream1_out -> path, $upstream2_out -> path,
77+ " Both upstream builds should resolve to the same content-addressed output path" );
78+
79+ my $downstream1 = $db -> resultset(' Builds' )-> find({
80+ jobset_id => $jobset -> id,
81+ job => " earlyCutoffDownstream1" ,
82+ });
83+ my $downstream2 = $db -> resultset(' Builds' )-> find({
84+ jobset_id => $jobset -> id,
85+ job => " earlyCutoffDownstream2" ,
86+ });
87+
88+ my $downstream1_out = $downstream1 -> buildoutputs-> find({ name => " out" });
89+ my $downstream2_out = $downstream2 -> buildoutputs-> find({ name => " out" });
90+ is($downstream1_out -> path, $downstream2_out -> path,
91+ " Both downstream builds should resolve to the same content-addressed output path" );
92+
93+ # TODO: Once the queue runner deduplicates steps by resolved derivation
94+ # path (not just original drv path), we should also verify that both
95+ # original steps resolve to steps with the same derivation. (Might even
96+ # be the same step, but that doesn't matter as much).
97+ #
98+ # If there are multiple steps for the single resolved derivation,
99+ # additionally, only one should get built, and the other should be a
100+ # cached successes (as is normal for duplicative build steps).
101+
59102done_testing;
60103
0 commit comments