@@ -342,7 +342,9 @@ func TestCoordinator_Execute(t *testing.T) {
342342}
343343
344344func TestCoordinator_Execute_StepCaching (t * testing.T ) {
345+ // Setup dependencies
345346 cache := newInMemoryExecutionCache ()
347+ logManager := mock.LogNoOpManager {}
346348
347349 task := & Task {
348350 Steps : []batches.Step {
@@ -370,46 +372,62 @@ func TestCoordinator_Execute_StepCaching(t *testing.T) {
370372 },
371373 }}
372374
375+ // Build Coordinator
376+ coord := & Coordinator {cache : cache , exec : executor , logManager : logManager }
377+
373378 // First execution. Make sure that the Task executes all steps.
374- execAndEnsure (t , cache , executor , task , assertNoCachedResult (t ))
379+ execAndEnsure (t , coord , executor , task , assertNoCachedResult (t ))
375380 // We now expect the cache to have 1+N entries: 1 for the complete task, N
376381 // for the steps.
377382 wantCacheSize := len (task .Steps ) + 1
378383 assertCacheSize (t , cache , wantCacheSize )
379384
385+ // Reset task
386+ task .CachedResultFound = false
387+
380388 // Change the 2nd step's definition:
381389 task .Steps [1 ].Run = `echo "two modified"`
382390 // Re-execution should start with the diff produced by steps[0] as the
383391 // start state from which steps[1] is then re-executed.
384- execAndEnsure (t , cache , executor , task , assertCachedResultForStep (t , 0 ))
392+ execAndEnsure (t , coord , executor , task , assertCachedResultForStep (t , 0 ))
385393 // Cache now contains old entries, plus another "complete task" entry and
386394 // two entries for newly executed steps.
387395 wantCacheSize += 1 + 2
388396 assertCacheSize (t , cache , wantCacheSize )
389397
398+ // Reset task
399+ task .CachedResultFound = false
400+
390401 // Change the 3rd step's definition:
391402 task .Steps [2 ].Run = `echo "three modified"`
392403 // Re-execution should use the diff from steps[1] as start state
393- execAndEnsure (t , cache , executor , task , assertCachedResultForStep (t , 1 ))
404+ execAndEnsure (t , coord , executor , task , assertCachedResultForStep (t , 1 ))
394405 // Cache now contains old entries, plus another "complete task" entry and
395406 // a single new step entry
396407 wantCacheSize += 1 + 1
397408 assertCacheSize (t , cache , wantCacheSize )
409+
410+ // Reset task
411+ task .CachedResultFound = false
412+
413+ // Now we execute the spec with -clear-cache:
414+ coord .opts .ClearCache = true
415+ // We don't want any cached results set on the task:
416+ execAndEnsure (t , coord , executor , task , assertNoCachedResult (t ))
417+ // Cache should have the same number of entries: the cached step results should
418+ // have been cleared (the complete-task-result is cleared in another
419+ // code path) and the same amount of cached entries has been added.
420+ assertCacheSize (t , cache , wantCacheSize )
398421}
399422
400423// execAndEnsure executes the given Task with the given cache and dummyExecutor
401424// in a new Coordinator, setting cb as the startCallback on the executor.
402- func execAndEnsure (t * testing.T , cache ExecutionCache , exec * dummyExecutor , task * Task , cb startCallback ) {
425+ func execAndEnsure (t * testing.T , coord * Coordinator , exec * dummyExecutor , task * Task , cb startCallback ) {
403426 t .Helper ()
404427
405- // Setup dependencies
406428 batchSpec := & batches.BatchSpec {ChangesetTemplate : testChangesetTemplate }
407- logManager := mock.LogNoOpManager {}
408429 noopPrinter := func ([]* TaskStatus ) {}
409430
410- // Build Coordinator
411- coord := & Coordinator {cache : cache , exec : exec , logManager : logManager }
412-
413431 // Set the ChangesetTemplate on Task
414432 task .Template = batchSpec .ChangesetTemplate
415433
0 commit comments