Skip to content

Commit

Permalink
Merge pull request #1118 from wakatime/misc/flakey-tests#2
Browse files Browse the repository at this point in the history
Fix flakey tests
  • Loading branch information
alanhamlett authored Nov 7, 2024
2 parents 4a194fb + 9a80ec2 commit b60c4da
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
28 changes: 17 additions & 11 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ func testSendHeartbeats(t *testing.T, projectFolder, entity, p string) {
offlineQueueFileLegacy, err := os.CreateTemp(tmpDir, "")
require.NoError(t, err)

defer offlineQueueFileLegacy.Close()
// close the file to avoid "file already closed" error
offlineQueueFileLegacy.Close()

tmpConfigFile, err := os.CreateTemp(tmpDir, "wakatime.cfg")
require.NoError(t, err)
Expand Down Expand Up @@ -215,7 +216,8 @@ func TestSendHeartbeats_SecondaryApiKey(t *testing.T) {
offlineQueueFileLegacy, err := os.CreateTemp(tmpDir, "")
require.NoError(t, err)

defer offlineQueueFileLegacy.Close()
// close the file to avoid "file already closed" error
offlineQueueFileLegacy.Close()

tmpInternalConfigFile, err := os.CreateTemp(tmpDir, "wakatime-internal.cfg")
require.NoError(t, err)
Expand Down Expand Up @@ -293,7 +295,8 @@ func TestSendHeartbeats_ExtraHeartbeats(t *testing.T) {
offlineQueueFileLegacy, err := os.CreateTemp(tmpDir, "")
require.NoError(t, err)

defer offlineQueueFileLegacy.Close()
// close the file to avoid "file already exists" error on Windows
offlineQueueFileLegacy.Close()

tmpConfigFile, err := os.CreateTemp(tmpDir, "wakatime.cfg")
require.NoError(t, err)
Expand Down Expand Up @@ -385,7 +388,7 @@ func TestSendHeartbeats_ExtraHeartbeats_SyncLegacyOfflineActivity(t *testing.T)
offlineQueueFileLegacy, err := os.CreateTemp(tmpDir, "legacy-offline-file")
require.NoError(t, err)

// early close to avoid file locking in Windows
// close the file to avoid "file already exists" error on Windows
offlineQueueFileLegacy.Close()

db, err := bolt.Open(offlineQueueFileLegacy.Name(), 0600, nil)
Expand Down Expand Up @@ -438,8 +441,6 @@ func TestSendHeartbeats_ExtraHeartbeats_SyncLegacyOfflineActivity(t *testing.T)

buffer := bytes.NewBuffer(data)

assert.FileExists(t, offlineQueueFileLegacy.Name())

runWakatimeCli(
t,
buffer,
Expand Down Expand Up @@ -529,7 +530,8 @@ func TestSendHeartbeats_Err(t *testing.T) {
offlineQueueFileLegacy, err := os.CreateTemp(tmpDir, "")
require.NoError(t, err)

defer offlineQueueFileLegacy.Close()
// close the file to avoid "file already exists" error on Windows
offlineQueueFileLegacy.Close()

tmpConfigFile, err := os.CreateTemp(tmpDir, "wakatime.cfg")
require.NoError(t, err)
Expand Down Expand Up @@ -590,7 +592,8 @@ func TestSendHeartbeats_ErrAuth_InvalidAPIKEY(t *testing.T) {
offlineQueueFileLegacy, err := os.CreateTemp(tmpDir, "")
require.NoError(t, err)

defer offlineQueueFileLegacy.Close()
// close the file to avoid "file already exists" error on Windows
offlineQueueFileLegacy.Close()

tmpConfigFile, err := os.CreateTemp(tmpDir, "wakatime.cfg")
require.NoError(t, err)
Expand Down Expand Up @@ -650,7 +653,8 @@ func TestSendHeartbeats_MalformedConfig(t *testing.T) {
offlineQueueFileLegacy, err := os.CreateTemp(tmpDir, "")
require.NoError(t, err)

defer offlineQueueFileLegacy.Close()
// close the file to avoid "file already exists" error on Windows
offlineQueueFileLegacy.Close()

out := runWakatimeCliExpectErr(
t,
Expand Down Expand Up @@ -684,7 +688,8 @@ func TestSendHeartbeats_MalformedInternalConfig(t *testing.T) {
offlineQueueFileLegacy, err := os.CreateTemp(tmpDir, "")
require.NoError(t, err)

defer offlineQueueFileLegacy.Close()
// close the file to avoid "file already exists" error on Windows
offlineQueueFileLegacy.Close()

tmpConfigFile, err := os.CreateTemp(tmpDir, "wakatime.cfg")
require.NoError(t, err)
Expand Down Expand Up @@ -1017,7 +1022,8 @@ func TestPrintOfflineHeartbeats(t *testing.T) {
offlineQueueFileLegacy, err := os.CreateTemp(tmpDir, "")
require.NoError(t, err)

defer offlineQueueFileLegacy.Close()
// close the file to avoid "file already exists" error on Windows
offlineQueueFileLegacy.Close()

tmpConfigFile, err := os.CreateTemp(tmpDir, "wakatime.cfg")
require.NoError(t, err)
Expand Down
5 changes: 3 additions & 2 deletions pkg/offline/legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"fmt"
"path/filepath"

"github.com/mitchellh/go-homedir"
"github.com/spf13/viper"
"github.com/wakatime/wakatime-cli/pkg/ini"
"github.com/wakatime/wakatime-cli/pkg/vipertools"

"github.com/mitchellh/go-homedir"
"github.com/spf13/viper"
)

// dbLegacyFilename is the legacy bolt db filename.
Expand Down

0 comments on commit b60c4da

Please sign in to comment.