Skip to content

Commit

Permalink
chore: fix race condition on init read (#409)
Browse files Browse the repository at this point in the history
Newly added tests showed flakiness - this is due to missing initial
fetch handling.

This PR improves tests only.

Signed-off-by: Kavindu Dodanduwa <kavindudodanduwa@gmail.com>
  • Loading branch information
Kavindu-Dodan authored Feb 13, 2023
1 parent b71729a commit 0c9eb23
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions pkg/sync/file/filepath_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,6 @@ func TestSimpleSync(t *testing.T) {
},
},
},
"empty-file-use-default": {
manipulationFuncs: []func(t *testing.T){
func(t *testing.T) {
writeToFile(t, "")
},
},
expectedDataSync: []sync.DataSync{
{
FlagData: defaultState,
Source: fmt.Sprintf("%s/%s", fetchDirName, fetchFileName),
Type: sync.ALL,
},
},
},
}

handler := Sync{
Expand All @@ -120,6 +106,12 @@ func TestSimpleSync(t *testing.T) {
}
}()

// file sync perform an initial fetch and then watch for file events
init := <-dataSyncChan
if init.FlagData != defaultState {
t.Errorf("initial fetch for empty file expected to return default state: %s", defaultState)
}

for i, manipulation := range tt.manipulationFuncs {
syncEvent := tt.expectedDataSync[i]
manipulation(t)
Expand Down

0 comments on commit 0c9eb23

Please sign in to comment.