mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-29 17:07:24 +02:00
skip configuration updates to the most recent one (#2690)
This commit is contained in:
parent
f22e34c8e0
commit
30664cd307
10 changed files with 667 additions and 5 deletions
74
pkg/grpc/databroker/fast_forward_test.go
Normal file
74
pkg/grpc/databroker/fast_forward_test.go
Normal file
|
@ -0,0 +1,74 @@
|
|||
package databroker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/rand"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
type mockFF struct {
|
||||
clear chan struct{}
|
||||
update chan uint64
|
||||
}
|
||||
|
||||
func (ff *mockFF) ClearRecords(ctx context.Context) {
|
||||
ff.clear <- struct{}{}
|
||||
}
|
||||
|
||||
func (ff *mockFF) UpdateRecords(ctx context.Context, sv uint64, records []*Record) {
|
||||
time.Sleep(time.Millisecond * time.Duration(rand.Intn(5)))
|
||||
ff.update <- sv
|
||||
}
|
||||
|
||||
func (ff *mockFF) GetDataBrokerServiceClient() DataBrokerServiceClient {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ff *mockFF) getUpdate(ctx context.Context) (uint64, error) {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return 0, ctx.Err()
|
||||
case sv := <-ff.update:
|
||||
return sv, nil
|
||||
}
|
||||
}
|
||||
|
||||
func TestFastForward(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*15)
|
||||
defer cancel()
|
||||
|
||||
m := &mockFF{
|
||||
clear: make(chan struct{}),
|
||||
update: make(chan uint64),
|
||||
}
|
||||
|
||||
f := newFastForwardHandler(ctx, m)
|
||||
|
||||
for x := 0; x < 100; x++ {
|
||||
n := rand.Intn(100) + 1
|
||||
for i := 1; i <= n; i++ {
|
||||
f.UpdateRecords(ctx, uint64(i), nil)
|
||||
}
|
||||
|
||||
var prev uint64
|
||||
assert.Eventually(t, func() bool {
|
||||
sv, err := m.getUpdate(ctx)
|
||||
require.NoError(t, err)
|
||||
assert.Less(t, prev, sv)
|
||||
prev = sv
|
||||
t.Log(x, sv)
|
||||
return int(sv) == n
|
||||
}, time.Second, time.Millisecond*10)
|
||||
|
||||
f.ClearRecords(ctx)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
t.Error("timed out")
|
||||
case <-m.clear:
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue