From 0c9eb2322df99b4216d40afd1cb3b8873b0c59ff Mon Sep 17 00:00:00 2001 From: Kavindu Dodanduwa Date: Mon, 13 Feb 2023 13:54:54 -0800 Subject: [PATCH] chore: fix race condition on init read (#409) Newly added tests showed flakiness - this is due to missing initial fetch handling. This PR improves tests only. Signed-off-by: Kavindu Dodanduwa --- pkg/sync/file/filepath_sync_test.go | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/pkg/sync/file/filepath_sync_test.go b/pkg/sync/file/filepath_sync_test.go index 950da625b..1d1de2f5f 100644 --- a/pkg/sync/file/filepath_sync_test.go +++ b/pkg/sync/file/filepath_sync_test.go @@ -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{ @@ -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)