Skip to content

Commit 4dae408

Browse files
authored
Remove unnecessary copy of serialized graph in tests. (#3904)
1 parent 1e5eda2 commit 4dae408

File tree

1 file changed

+27
-103
lines changed

1 file changed

+27
-103
lines changed

build_runner_core/test/generate/build_test.dart

Lines changed: 27 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,6 +1478,10 @@ void main() {
14781478
});
14791479

14801480
group('incremental builds with cached graph', () {
1481+
// Using `resumeFrom: result` to pass the filesystem between `testBuilders`
1482+
// calls causes the serialized graph from the previous build to be loaded,
1483+
// exactly as in real builds.
1484+
14811485
test('one new asset, one modified asset, one unchanged asset', () async {
14821486
var builders = [copyABuilderApplication];
14831487

@@ -1489,9 +1493,6 @@ void main() {
14891493
);
14901494

14911495
// Followup build with modified inputs.
1492-
var serializedGraph = result.readerWriter.testing.readBytes(
1493-
makeAssetId('a|$assetGraphPath'),
1494-
);
14951496
await testBuilders(
14961497
builders,
14971498
{
@@ -1500,7 +1501,6 @@ void main() {
15001501
'a|lib/b.txt': 'b',
15011502
'a|lib/b.txt.copy': 'b',
15021503
'a|lib/c.txt': 'c',
1503-
'a|$assetGraphPath': serializedGraph,
15041504
},
15051505
outputs: {'a|web/a.txt.copy': 'a2', 'a|lib/c.txt.copy': 'c'},
15061506
resumeFrom: result,
@@ -1528,17 +1528,10 @@ void main() {
15281528
);
15291529

15301530
// Followup build with the 2nd output missing.
1531-
var serializedGraph = result.readerWriter.testing.readBytes(
1532-
makeAssetId('a|$assetGraphPath'),
1533-
);
15341531
result.readerWriter.testing.delete(AssetId('a', 'lib/a.txt.2'));
15351532
await testBuilders(
15361533
builders,
1537-
{
1538-
'a|lib/a.txt': 'a',
1539-
'a|lib/a.txt.1': 'a',
1540-
'a|$assetGraphPath': serializedGraph,
1541-
},
1534+
{'a|lib/a.txt': 'a', 'a|lib/a.txt.1': 'a'},
15421535
outputs: {'a|lib/a.txt.1': 'a', 'a|lib/a.txt.2': 'a'},
15431536
resumeFrom: result,
15441537
);
@@ -1581,51 +1574,39 @@ void main() {
15811574
);
15821575

15831576
// Followup build with modified unused inputs should have no outputs.
1584-
var serializedGraph = result.readerWriter.testing.readBytes(
1585-
makeAssetId('a|$assetGraphPath'),
1586-
);
15871577
await testBuilders(
15881578
builders,
15891579
{
15901580
'a|lib/a.txt': 'a',
15911581
'a|lib/a.txt.used': 'b',
15921582
'a|lib/a.txt.unused': 'd', // changed the content of this one
15931583
'a|lib/a.txt.copy': 'ab',
1594-
'a|$assetGraphPath': serializedGraph,
15951584
},
15961585
outputs: {},
15971586
resumeFrom: result,
15981587
);
15991588

16001589
// And now modify a real input.
1601-
serializedGraph = result.readerWriter.testing.readBytes(
1602-
makeAssetId('a|$assetGraphPath'),
1603-
);
16041590
await testBuilders(
16051591
builders,
16061592
{
16071593
'a|lib/a.txt': 'a',
16081594
'a|lib/a.txt.used': 'e',
16091595
'a|lib/a.txt.unused': 'd',
16101596
'a|lib/a.txt.copy': 'ab',
1611-
'a|$assetGraphPath': serializedGraph,
16121597
},
16131598
outputs: {'a|lib/a.txt.copy': 'ae'},
16141599
resumeFrom: result,
16151600
);
16161601

16171602
// Finally modify the primary input.
1618-
serializedGraph = result.readerWriter.testing.readBytes(
1619-
makeAssetId('a|$assetGraphPath'),
1620-
);
16211603
await testBuilders(
16221604
builders,
16231605
{
16241606
'a|lib/a.txt': 'f',
16251607
'a|lib/a.txt.used': 'e',
16261608
'a|lib/a.txt.unused': 'd',
16271609
'a|lib/a.txt.copy': 'ae',
1628-
'a|$assetGraphPath': serializedGraph,
16291610
},
16301611
outputs: {'a|lib/a.txt.copy': 'fe'},
16311612
resumeFrom: result,
@@ -1653,32 +1634,20 @@ void main() {
16531634
);
16541635

16551636
// Followup build with modified primary input should have no outputs.
1656-
var serializedGraph = result.readerWriter.testing.readBytes(
1657-
makeAssetId('a|$assetGraphPath'),
1658-
);
16591637
await testBuilders(
16601638
builders,
1661-
{
1662-
'a|lib/a.txt': 'b',
1663-
'a|lib/a.txt.used': '',
1664-
'a|lib/a.txt.copy': 'a',
1665-
'a|$assetGraphPath': serializedGraph,
1666-
},
1639+
{'a|lib/a.txt': 'b', 'a|lib/a.txt.used': '', 'a|lib/a.txt.copy': 'a'},
16671640
outputs: {},
16681641
resumeFrom: result,
16691642
);
16701643

16711644
// But modifying other inputs still causes a rebuild.
1672-
serializedGraph = result.readerWriter.testing.readBytes(
1673-
makeAssetId('a|$assetGraphPath'),
1674-
);
16751645
await testBuilders(
16761646
builders,
16771647
{
16781648
'a|lib/a.txt': 'b',
16791649
'a|lib/a.txt.used': 'b',
16801650
'a|lib/a.txt.copy': 'a',
1681-
'a|$assetGraphPath': serializedGraph,
16821651
},
16831652
outputs: {'a|lib/a.txt.copy': 'b'},
16841653
resumeFrom: result,
@@ -1706,13 +1675,10 @@ void main() {
17061675
);
17071676

17081677
// Delete the primary input, the output shoud still be deleted
1709-
var serializedGraph = result.readerWriter.testing.readBytes(
1710-
makeAssetId('a|$assetGraphPath'),
1711-
);
17121678
result.readerWriter.testing.delete(AssetId('a', 'lib/a.txt'));
17131679
await testBuilders(
17141680
builders,
1715-
{'a|lib/a.txt.copy': 'a', 'a|$assetGraphPath': serializedGraph},
1681+
{'a|lib/a.txt.copy': 'a'},
17161682
outputs: {},
17171683
resumeFrom: result,
17181684
);
@@ -1743,17 +1709,10 @@ void main() {
17431709
);
17441710

17451711
// Followup build with deleted input + cached graph.
1746-
var serializedGraph = result.readerWriter.testing.readBytes(
1747-
makeAssetId('a|$assetGraphPath'),
1748-
);
17491712
result.readerWriter.testing.delete(AssetId('a', 'lib/a.txt'));
17501713
await testBuilders(
17511714
builders,
1752-
{
1753-
'a|lib/a.txt.copy': 'a',
1754-
'a|lib/a.txt.clone': 'a',
1755-
'a|$assetGraphPath': serializedGraph,
1756-
},
1715+
{'a|lib/a.txt.copy': 'a', 'a|lib/a.txt.clone': 'a'},
17571716
outputs: {},
17581717
resumeFrom: result,
17591718
);
@@ -1784,14 +1743,7 @@ void main() {
17841743
);
17851744

17861745
// Followup build with same sources + cached graph.
1787-
var serializedGraph = result.readerWriter.testing.readBytes(
1788-
makeAssetId('a|$assetGraphPath'),
1789-
);
1790-
await testBuilders(builders, {
1791-
'a|web/a.txt': 'a',
1792-
'a|web/a.txt.copy': 'a',
1793-
'a|$assetGraphPath': serializedGraph,
1794-
}, outputs: {});
1746+
await testBuilders(builders, {}, outputs: {}, resumeFrom: result);
17951747
});
17961748

17971749
test('no outputs if no changed sources using `hideOutput: true`', () async {
@@ -1809,14 +1761,7 @@ void main() {
18091761
);
18101762

18111763
// Followup build with same sources + cached graph.
1812-
var serializedGraph = result.readerWriter.testing.readBytes(
1813-
makeAssetId('a|$assetGraphPath'),
1814-
);
1815-
await testBuilders(builders, {
1816-
'a|web/a.txt': 'a',
1817-
'a|web/a.txt.copy': 'a',
1818-
'a|$assetGraphPath': serializedGraph,
1819-
}, outputs: {});
1764+
await testBuilders(builders, {}, outputs: {}, resumeFrom: result);
18201765
});
18211766

18221767
test('inputs/outputs are updated if they change', () async {
@@ -1836,10 +1781,6 @@ void main() {
18361781

18371782
// Followup build with same sources + cached graph, but configure the
18381783
// builder to read a different file.
1839-
var serializedGraph = result.readerWriter.testing.readBytes(
1840-
makeAssetId('a|$assetGraphPath'),
1841-
);
1842-
18431784
await testBuilders(
18441785
[
18451786
applyToRoot(
@@ -1856,7 +1797,6 @@ void main() {
18561797
// builder but pretending its the same.
18571798
'a|lib/file.b': 'b2',
18581799
'a|lib/file.c': 'c',
1859-
'a|$assetGraphPath': serializedGraph,
18601800
},
18611801
outputs: {'a|lib/file.a.copy': 'c'},
18621802
resumeFrom: result,
@@ -1901,17 +1841,13 @@ void main() {
19011841

19021842
// Modify the primary input of `file.a.copy`, but its output doesn't
19031843
// change so `file.a.copy.copy` shouldn't be rebuilt.
1904-
var serializedGraph = result.readerWriter.testing.readBytes(
1905-
makeAssetId('a|$assetGraphPath'),
1906-
);
19071844
await testBuilders(
19081845
builders,
19091846
{
19101847
'a|lib/file.a': 'a2',
19111848
'a|lib/file.b': 'b',
19121849
'a|lib/file.a.copy': 'b',
19131850
'a|lib/file.a.copy.copy': 'b',
1914-
'a|$assetGraphPath': serializedGraph,
19151851
},
19161852
outputs: {'a|lib/file.a.copy': 'b'},
19171853
resumeFrom: result,
@@ -1922,22 +1858,24 @@ void main() {
19221858
var builders = [applyToRoot(SiblingCopyBuilder())];
19231859

19241860
// Initial build.
1925-
final result = await testBuilders(
1861+
var result = await testBuilders(
19261862
builders,
19271863
{'a|web/a.txt': 'a', 'a|web/a.txt.sibling': 'sibling'},
19281864
outputs: {'a|web/a.txt.new': 'sibling'},
19291865
);
19301866

19311867
// Followup build with cached graph and a changed primary input, but the
19321868
// actual file that was read has not changed.
1933-
await testBuilders(builders, {
1934-
'a|web/a.txt': 'b',
1935-
'a|web/a.txt.sibling': 'sibling',
1936-
'a|web/a.txt.new': 'sibling',
1937-
'a|$assetGraphPath': result.readerWriter.testing.readBytes(
1938-
makeAssetId('a|$assetGraphPath'),
1939-
),
1940-
}, outputs: {});
1869+
result = await testBuilders(
1870+
builders,
1871+
{
1872+
'a|web/a.txt': 'b',
1873+
'a|web/a.txt.sibling': 'sibling',
1874+
'a|web/a.txt.new': 'sibling',
1875+
},
1876+
outputs: {},
1877+
resumeFrom: result,
1878+
);
19411879

19421880
// And now try modifying the sibling to make sure that still works.
19431881
await testBuilders(
@@ -1946,11 +1884,9 @@ void main() {
19461884
'a|web/a.txt': 'b',
19471885
'a|web/a.txt.sibling': 'new!',
19481886
'a|web/a.txt.new': 'sibling',
1949-
'a|$assetGraphPath': result.readerWriter.testing.readBytes(
1950-
makeAssetId('a|$assetGraphPath'),
1951-
),
19521887
},
19531888
outputs: {'a|web/a.txt.new': 'new!'},
1889+
resumeFrom: result,
19541890
);
19551891
});
19561892
});
@@ -1986,13 +1922,9 @@ void main() {
19861922
'a|lib/a.source': 'true',
19871923
}, status: BuildStatus.failure);
19881924

1989-
var serializedGraph = result.readerWriter.testing.readBytes(
1990-
makeAssetId('a|$assetGraphPath'),
1991-
);
1992-
19931925
await testBuilders(
19941926
builders,
1995-
{'a|lib/a.source': 'false', 'a|$assetGraphPath': serializedGraph},
1927+
{'a|lib/a.source': 'false'},
19961928
outputs: {},
19971929
resumeFrom: result,
19981930
);
@@ -2070,30 +2002,22 @@ void main() {
20702002
),
20712003
),
20722004
];
2073-
final result = await testBuilders(builders, {
2005+
var result = await testBuilders(builders, {
20742006
'a|web/a.source': 'true',
20752007
}, status: BuildStatus.failure);
20762008

2077-
var serializedGraph = result.readerWriter.testing.readBytes(
2078-
makeAssetId('a|$assetGraphPath'),
2079-
);
2080-
2081-
await testBuilders(
2009+
result = await testBuilders(
20822010
builders,
2083-
{'a|web/a.source': 'false', 'a|$assetGraphPath': serializedGraph},
2011+
{'a|web/a.source': 'false'},
20842012
outputs: {'a|web/a.g1': '', 'a|web/a.g2': '', 'a|web/a.g3': ''},
20852013
resumeFrom: result,
20862014
);
20872015

2088-
serializedGraph = result.readerWriter.testing.readBytes(
2089-
makeAssetId('a|$assetGraphPath'),
2090-
);
2091-
20922016
// Make sure if we mark the original node as a failure again, that we
20932017
// also mark all its primary outputs as failures.
20942018
await testBuilders(
20952019
builders,
2096-
{'a|web/a.source': 'true', 'a|$assetGraphPath': serializedGraph},
2020+
{'a|web/a.source': 'true'},
20972021
outputs: {},
20982022
status: BuildStatus.failure,
20992023
resumeFrom: result,

0 commit comments

Comments
 (0)