pulumi/sdk/go/common/workspace/creds_test.go
Luke Hoban b45b3ed543
Re-apply #5857 (#5893)
This re-applies the fix in 5857 to make credentials.json writes concurrency safe.

The original fix used `path.Dir` instead of `filepath.Dir` - which led to not placing the temp file in the same folder (and drive) as the renamed file target.  This led to errors on Windows environments where the working directory was on a different drive than the `~/.pulumi` directory.  The change to use `filepath.Dir` instead ensures that even on Windows, the true directory containing the credentials file is used for the temp file as well.

Fixes #3877.
2020-12-08 17:38:59 -08:00

31 lines
486 B
Go

package workspace
import (
"sync"
"testing"
"github.com/stretchr/testify/assert"
)
func TestConcurrentCredentialsWrites(t *testing.T) {
creds, err := GetStoredCredentials()
assert.NoError(t, err)
var wg sync.WaitGroup
for i := 0; i < 1000; i++ {
wg.Add(2)
go func() {
defer wg.Done()
err := StoreCredentials(creds)
assert.NoError(t, err)
}()
go func() {
defer wg.Done()
_, err := GetStoredCredentials()
assert.NoError(t, err)
}()
}
wg.Wait()
}