Skip to content

Commit

Permalink
Fix race condition in test
Browse files Browse the repository at this point in the history
  • Loading branch information
alanhamlett committed Jul 29, 2024
1 parent 4b4c192 commit 070070c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
4 changes: 2 additions & 2 deletions cmd/heartbeat/heartbeat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ func TestSendHeartbeats_RateLimited(t *testing.T) {
numCalls++
})

tmpFile, err := os.CreateTemp(t.TempDir(), "wakatime")
tmpFile, err := os.CreateTemp(t.TempDir(), "wakatime-internal-config")
require.NoError(t, err)

offlineQueueFile, err := os.CreateTemp(t.TempDir(), "")
offlineQueueFile, err := os.CreateTemp(t.TempDir(), "offline-queue-file")
require.NoError(t, err)

v := viper.New()
Expand Down
16 changes: 6 additions & 10 deletions cmd/params/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2629,12 +2629,10 @@ func TestLoadHeartbeatParams_ExtraHeartbeats_StdinReadOnlyOnce(t *testing.T) {
data, err := os.ReadFile("testdata/extra_heartbeats.json")
require.NoError(t, err)

go func() {
_, err := w.Write(data)
require.NoError(t, err)
_, err = w.Write(data)
require.NoError(t, err)

w.Close()
}()
w.Close()

v := viper.New()
v.Set("entity", "/path/to/file")
Expand All @@ -2656,12 +2654,10 @@ func TestLoadHeartbeatParams_ExtraHeartbeats_StdinReadOnlyOnce(t *testing.T) {
data, err = os.ReadFile("testdata/extra_heartbeats_with_string_values.json")
require.NoError(t, err)

go func() {
_, err := w.Write(data)
require.NoError(t, err)
_, err = w.Write(data)
require.NoError(t, err)

w.Close()
}()
w.Close()

os.Stdin = r

Expand Down

0 comments on commit 070070c

Please sign in to comment.