Enable concurrent process to construct persistent caches (#23619)
This commit is contained in:
Родитель
a6f7621bba
Коммит
914a37f9c7
|
@ -7,6 +7,7 @@
|
|||
### Breaking Changes
|
||||
|
||||
### Bugs Fixed
|
||||
* `New` no longer returns an error when called simultaneously in two processes
|
||||
|
||||
### Other Changes
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"time"
|
||||
|
@ -29,14 +30,16 @@ var (
|
|||
// tryStorage tests the storage implementation by round-tripping data
|
||||
tryStorage = func() {
|
||||
const errFmt = "persistent storage isn't available due to error %q"
|
||||
s, err := storage("azidentity-test-cache")
|
||||
// random content prevents conflict with concurrent processes executing this function
|
||||
n := fmt.Sprint(rand.Int())
|
||||
s, err := storage("azidentity-test" + n)
|
||||
if err != nil {
|
||||
storageError = fmt.Errorf(errFmt, err)
|
||||
return
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
||||
defer cancel()
|
||||
in := []byte("test")
|
||||
in := []byte(n)
|
||||
err = s.Write(ctx, in)
|
||||
if err != nil {
|
||||
storageError = fmt.Errorf(errFmt, err)
|
||||
|
@ -48,7 +51,7 @@ var (
|
|||
return
|
||||
}
|
||||
if !bytes.Equal(in, out) {
|
||||
storageError = fmt.Errorf(errFmt, "read doesn't match write")
|
||||
storageError = fmt.Errorf(errFmt, "reading or writing cache data failed")
|
||||
}
|
||||
err = s.Delete(ctx)
|
||||
if err != nil {
|
||||
|
|
Загрузка…
Ссылка в новой задаче