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.
30 lines
486 B
Go
30 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()
|
|
}
|