forked from qlik-oss/enigma-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pending_call_registry_test.go
39 lines (28 loc) · 978 Bytes
/
pending_call_registry_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package enigma
import (
"context"
"github.com/stretchr/testify/assert"
"testing"
)
func TestPendingCallRegistry(t *testing.T) {
ctx := context.Background()
// Setup call registry
pcr := newPendingCallRegistry()
// Register calls
pc1 := pcr.registerPendingCall(ctx)
ctxWithReservedRequestID, reservedRequestID := pcr.WithReservedRequestID(ctx)
pc2 := pcr.registerPendingCall(ctx)
pc3 := pcr.registerPendingCall(ctxWithReservedRequestID)
// Check that the third registered call actually uses the reserved request id
assert.Equal(t, reservedRequestID, pc3.ID)
// Extract pending calls
extractedpc2 := pcr.removePendingCall(pc2.ID)
assert.Equal(t, pc2, extractedpc2)
extractedpc1 := pcr.removePendingCall(pc1.ID)
assert.Equal(t, pc1, extractedpc1)
extractedpc3 := pcr.removePendingCall(pc3.ID)
assert.Equal(t, pc3, extractedpc3)
// Extract twice should return nil
doubleExtracted1 := pcr.removePendingCall(pc1.ID)
assert.Nil(t, doubleExtracted1)
}