mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-28 00:17:34 +02:00
fix concurrency race (#1675)
This commit is contained in:
parent
6e33067eef
commit
35f871ad42
2 changed files with 37 additions and 4 deletions
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"golang.org/x/sync/errgroup"
|
||||
"google.golang.org/protobuf/types/known/anypb"
|
||||
)
|
||||
|
||||
|
@ -85,3 +86,23 @@ func TestDB(t *testing.T) {
|
|||
assert.Nil(t, record)
|
||||
})
|
||||
}
|
||||
|
||||
func TestConcurrency(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db := NewDB("example", 2)
|
||||
|
||||
eg, ctx := errgroup.WithContext(ctx)
|
||||
eg.Go(func() error {
|
||||
for i := 0; i < 1000; i++ {
|
||||
_, _ = db.List(ctx, "")
|
||||
}
|
||||
return nil
|
||||
})
|
||||
eg.Go(func() error {
|
||||
for i := 0; i < 1000; i++ {
|
||||
db.Put(ctx, fmt.Sprint(i), new(anypb.Any))
|
||||
}
|
||||
return nil
|
||||
})
|
||||
eg.Wait()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue