Skip to content

Commit

Permalink
table: Fix race in file_table reload test
Browse files Browse the repository at this point in the history
O_SYNC should be used to make sure other thread running concurrently
will see the change.
  • Loading branch information
foxcpp committed Feb 29, 2020
1 parent 42fc92c commit a91d8c2
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions internal/table/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,14 @@ func TestFileReload_Broken(t *testing.T) {
t.Fatal(err)
}

// This delay is somehow important. Not sure why.
time.Sleep(250 * time.Millisecond)

if err := ioutil.WriteFile(f.Name(), []byte(":"), os.ModePerm); err != nil {
f2, err := os.OpenFile(f.Name(), os.O_WRONLY|os.O_SYNC, os.ModePerm)
if err != nil {
t.Fatal(err)
}
if _, err := f2.WriteString(":"); err != nil {
t.Fatal(err)
}
defer f2.Close()

time.Sleep(3 * reloadInterval)

Expand Down

0 comments on commit a91d8c2

Please sign in to comment.