Skip to content

Commit

Permalink
tests: added clause that grants another 400ms to tests before failing…
Browse files Browse the repository at this point in the history
… them
  • Loading branch information
MadsRC committed May 19, 2024
1 parent 9f46400 commit f6356f9
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions internal/configProvider/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,17 +242,27 @@ func TestNewConfigProvider(t *testing.T) {
// change and reload the config
time.Sleep(100 * time.Millisecond)

assert.Equal(t, newPasswordString, c.k.String(databasePasswordKey))
// Ensure that the config has been updated - Allow for one failure to account
// for potentially slow CI runners.
if !assert.Equal(t, newPasswordString, c.k.String(databasePasswordKey)) {
time.Sleep(400 * time.Millisecond)
require.Equal(t, newPasswordString, c.k.String(databasePasswordKey))
}

badYamlContent := []byte{0x00, 0x01, 0x02}
err = os.WriteFile(tempFile, badYamlContent, 0644)
require.NoError(t, err)

time.Sleep(100 * time.Millisecond)

// Ensure that the config has been updated - Allow for one failure to account
// for potentially slow CI runners.
// The bad yaml content should not have been loaded and thus the previous
// value should still be present.
assert.Equal(t, newPasswordString, c.k.String(databasePasswordKey))
if !assert.Equal(t, newPasswordString, c.k.String(databasePasswordKey)) {
time.Sleep(400 * time.Millisecond)
require.Equal(t, newPasswordString, c.k.String(databasePasswordKey))
}
}

func TestNewConfigProviderErrorNoYamlFile(t *testing.T) {
Expand Down Expand Up @@ -287,7 +297,12 @@ func TestNewConfigProviderErrorUpdateFailValidate(t *testing.T) {
require.NoError(t, err)

time.Sleep(100 * time.Millisecond)
require.Equal(t, 5432, cfg.Database.Port)
// Ensure that the config has been updated - Allow for one failure to account
// for potentially slow CI runners.
if !assert.Equal(t, 5432, cfg.Database.Port) {
time.Sleep(400 * time.Millisecond)
require.Equal(t, 5432, cfg.Database.Port)
}
}

func TestNewConfigProviderErrorValidateYamlFile(t *testing.T) {
Expand Down Expand Up @@ -331,8 +346,12 @@ func TestConfigProviderGet(t *testing.T) {
time.Sleep(100 * time.Millisecond)

require.NotNil(t, cfg)
// Ensure that the config has been updated
require.Equal(t, newPasswordString, cfg.Database.Password)
// Ensure that the config has been updated - Allow for one failure to account
// for potentially slow CI runners.
if !assert.Equal(t, newPasswordString, cfg.Database.Password) {
time.Sleep(400 * time.Millisecond)
require.Equal(t, newPasswordString, cfg.Database.Password)
}
// Ensure that the other values have not changed
require.Equal(t, "postgres", cfg.Database.User)
require.Equal(t, "localhost", cfg.Database.Host)
Expand All @@ -348,7 +367,12 @@ func TestConfigProviderGet(t *testing.T) {
// The bad yaml content should not have been loaded and thus the previous
// value should still be present.
require.NotNil(t, cfg)
require.Equal(t, newPasswordString, cfg.Database.Password)
// Ensure that the config has been updated - Allow for one failure to account
// for potentially slow CI runners.
if !assert.Equal(t, newPasswordString, cfg.Database.Password) {
time.Sleep(400 * time.Millisecond)
require.Equal(t, newPasswordString, cfg.Database.Password)
}
require.Equal(t, "postgres", cfg.Database.User)
require.Equal(t, "localhost", cfg.Database.Host)
require.Equal(t, 5432, cfg.Database.Port)
Expand Down

0 comments on commit f6356f9

Please sign in to comment.