Skip to content

Commit

Permalink
feat: Adding a little bit of a sleep for test data races
Browse files Browse the repository at this point in the history
  • Loading branch information
devanbenz committed Jan 7, 2025
1 parent c30a168 commit 216bba3
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions query/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,6 @@ func (m *mockWatcher) Contains(substr string) bool {
}

func TestQueryExecutor_WriteQueryToLog(t *testing.T) {
t.Parallel()
q, err := influxql.ParseQuery(`SELECT count(value) FROM cpu`)
require.NoError(t, err, "parse query")

Expand All @@ -742,10 +741,11 @@ func TestQueryExecutor_WriteQueryToLog(t *testing.T) {
discardOutput(e.ExecuteQuery(q, query.ExecutionOptions{}, nil))

require.True(t, mockWatcher.Contains(`SELECT count(value) FROM cpu`))
err = mockWatcher.Close()
require.NoError(t, err)
}

func TestQueryExecutor_IgnoreWriteEvent(t *testing.T) {
t.Parallel()
q, err := influxql.ParseQuery(`SELECT count(value) FROM cpu`)
require.NoError(t, err, "parse query")

Expand All @@ -765,7 +765,6 @@ func TestQueryExecutor_IgnoreWriteEvent(t *testing.T) {

require.True(t, mockWatcher.Contains(`SELECT count(value) FROM cpu`))
require.Equal(t, uint64(0), mockWatcher.RemovedPaths.Load())
require.Equal(t, uint64(1), mockWatcher.AddedPaths.Load())
require.Equal(t, uint64(0), mockWatcher.ChangeEvents.Load())

mockWatcher.MockEvents <- fsnotify.Event{
Expand All @@ -774,10 +773,12 @@ func TestQueryExecutor_IgnoreWriteEvent(t *testing.T) {
}
// Should not register a write event as a change event
require.Equal(t, uint64(0), mockWatcher.ChangeEvents.Load())

err = mockWatcher.Close()
require.NoError(t, err)
}

func TestQueryExecutor_ChangeEvent(t *testing.T) {
t.Parallel()
q, err := influxql.ParseQuery(`SELECT count(value) FROM cpu`)
require.NoError(t, err, "parse query")

Expand Down Expand Up @@ -805,6 +806,8 @@ func TestQueryExecutor_ChangeEvent(t *testing.T) {
Op: fsnotify.Rename,
}

time.Sleep(10 * time.Millisecond)

q, err = influxql.ParseQuery(`SELECT count(value) FROM mem`)

e.StatementExecutor = &StatementExecutor{
Expand All @@ -819,10 +822,13 @@ func TestQueryExecutor_ChangeEvent(t *testing.T) {
require.True(t, mockWatcher.Contains(`SELECT count(value) FROM mem`))

require.Equal(t, uint64(1), mockWatcher.ChangeEvents.Load())
require.Equal(t, uint64(1), mockWatcher.RemovedPaths.Load())

err = mockWatcher.Close()
require.NoError(t, err)
}

func TestQueryExecutor_RemoveEvent(t *testing.T) {
t.Parallel()
q, err := influxql.ParseQuery(`SELECT count(value) FROM cpu`)
require.NoError(t, err, "parse query")

Expand Down Expand Up @@ -850,6 +856,8 @@ func TestQueryExecutor_RemoveEvent(t *testing.T) {
Op: fsnotify.Remove,
}

time.Sleep(10 * time.Millisecond)

q, err = influxql.ParseQuery(`SELECT count(value) FROM mem`)

e.StatementExecutor = &StatementExecutor{
Expand All @@ -864,6 +872,10 @@ func TestQueryExecutor_RemoveEvent(t *testing.T) {
require.True(t, mockWatcher.Contains(`SELECT count(value) FROM mem`))

require.Equal(t, uint64(1), mockWatcher.ChangeEvents.Load())
require.Equal(t, uint64(1), mockWatcher.RemovedPaths.Load())

err = mockWatcher.Close()
require.NoError(t, err)
}

func discardOutput(results <-chan *query.Result) {
Expand Down

0 comments on commit 216bba3

Please sign in to comment.