@@ -112,6 +112,12 @@ func TestChecksumSymlinkNoParentScan(t *testing.T) {
112
112
113
113
// https://github.com/moby/buildkit/issues/5042
114
114
func TestNeedScanChecksumRegression (t * testing.T ) {
115
+ // This test cannot be run in parallel because we use scanCounter.
116
+ scanCounterEnable = true
117
+ defer func () {
118
+ scanCounterEnable = false
119
+ }()
120
+
115
121
tmpdir := t .TempDir ()
116
122
117
123
snapshotter , err := native .NewSnapshotter (filepath .Join (tmpdir , "snapshots" ))
@@ -166,11 +172,22 @@ func TestNeedScanChecksumRegression(t *testing.T) {
166
172
require .Equalf (t , test .expectNeedsScan , needs , "needsScan(%q, followTrailing=%v)" , test .path , test .followTrailing )
167
173
}
168
174
175
+ // Make sure trying to checksum a subpath results in no further scans.
176
+ initialScanCounter := scanCounter .Load ()
177
+ _ , err = cc .Checksum (context .TODO (), ref , "/bb/cc" , ChecksumOpts {FollowLinks : true }, nil )
178
+ require .NoError (t , err )
179
+ require .Equal (t , initialScanCounter , scanCounter .Load ())
180
+ _ , err = cc .Checksum (context .TODO (), ref , "/bb/non-existent" , ChecksumOpts {FollowLinks : true }, nil )
181
+ require .Error (t , err )
182
+ require .Equal (t , initialScanCounter , scanCounter .Load ())
183
+
169
184
// Looking up a non-existent path in / will checksum the whole tree. See
170
185
// <https://github.com/moby/buildkit/issues/5042> for more information.
171
186
// This means that needsScan will return true for any path.
172
187
_ , err = cc .Checksum (context .TODO (), ref , "/non-existent" , ChecksumOpts {FollowLinks : true }, nil )
173
188
require .Error (t , err )
189
+ fullScanCounter := scanCounter .Load ()
190
+ require .NotEqual (t , fullScanCounter , initialScanCounter )
174
191
175
192
root = cc .tree .Root ()
176
193
for _ , path := range []string {
@@ -184,6 +201,21 @@ func TestNeedScanChecksumRegression(t *testing.T) {
184
201
require .NoErrorf (t , err , "needsScan(%q, followTrailing=true)" , path )
185
202
require .Falsef (t , needs2 , "needsScan(%q, followTrailing=true)" , path )
186
203
}
204
+
205
+ // Looking up any more paths should not result in any more scans because we
206
+ // already know / was scanned.
207
+ _ , err = cc .Checksum (context .TODO (), ref , "/non-existent" , ChecksumOpts {FollowLinks : true }, nil )
208
+ require .Error (t , err )
209
+ require .Equal (t , fullScanCounter , scanCounter .Load ())
210
+ _ , err = cc .Checksum (context .TODO (), ref , "/different/non/existent" , ChecksumOpts {FollowLinks : true }, nil )
211
+ require .Error (t , err )
212
+ require .Equal (t , fullScanCounter , scanCounter .Load ())
213
+ _ , err = cc .Checksum (context .TODO (), ref , "/aa/root/aa/non-exist" , ChecksumOpts {FollowLinks : true }, nil )
214
+ require .Error (t , err )
215
+ require .Equal (t , fullScanCounter , scanCounter .Load ())
216
+ _ , err = cc .Checksum (context .TODO (), ref , "/aa/root/bb/cc" , ChecksumOpts {FollowLinks : true }, nil )
217
+ require .NoError (t , err )
218
+ require .Equal (t , fullScanCounter , scanCounter .Load ())
187
219
}
188
220
189
221
func TestChecksumNonLexicalSymlinks (t * testing.T ) {
0 commit comments