MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / TestConcurrentRefreshUser

Function TestConcurrentRefreshUser

rest/blip_api_crud_test.go:1008–1147  ·  view source on GitHub ↗

Start subChanges w/ continuous=true, batchsize=20 Start sending rev messages for documents that grant access to themselves for the active replication's user

(t *testing.T)

Source from the content-addressed store, hash-verified

1006// Start subChanges w/ continuous=true, batchsize=20
1007// Start sending rev messages for documents that grant access to themselves for the active replication's user
1008func TestConcurrentRefreshUser(t *testing.T) {
1009 base.SetUpTestLogging(t, base.LevelInfo, base.KeyHTTP, base.KeySync, base.KeySyncMsg, base.KeyChanges, base.KeyCache)
1010 // Initialize restTester here, so that we can use custom sync function, and later modify user
1011 syncFunction := `
1012function(doc, oldDoc) {
1013 access(doc.accessUser, doc.accessChannel)
1014 channel(doc.channels)
1015}
1016
1017`
1018 rtConfig := RestTesterConfig{SyncFn: syncFunction}
1019 rt := NewRestTester(t, &rtConfig)
1020 defer rt.Close()
1021
1022 const user1 = "user1"
1023 rt.CreateUser(user1, nil)
1024 // Create bliptester that is connected as user1, with no access to channel ABC
1025 bt := NewBlipTesterFromSpecWithRT(rt, &BlipTesterSpec{
1026 connectingUsername: user1,
1027 })
1028 defer bt.Close()
1029
1030 // Counter/Waitgroup to help ensure that all callbacks on continuous changes handler are received
1031 receivedChangesWg := sync.WaitGroup{}
1032 revsFinishedWg := sync.WaitGroup{}
1033
1034 // When this test sends subChanges, Sync Gateway will send a changes request that must be handled
1035 lastReceivedSeq := float64(0)
1036 var numbatchesReceived int32
1037 nonIntegerSequenceReceived := false
1038 changeCount := 0
1039 bt.blipContext.HandlerForProfile["changes"] = func(request *blip.Message) {
1040
1041 body, err := request.Body()
1042 require.NoError(t, err)
1043 responseVal := [][]interface{}{}
1044 if string(body) != "null" {
1045
1046 atomic.AddInt32(&numbatchesReceived, 1)
1047
1048 // Expected changes body: [[1,"foo","1-abc"]]
1049 changeListReceived := [][]interface{}{}
1050 err = base.JSONUnmarshal(body, &changeListReceived)
1051 assert.NoError(t, err, "Error unmarshalling changes received")
1052
1053 for _, change := range changeListReceived {
1054
1055 // The change should have three items in the array
1056 // [1,"foo","1-abc"]
1057 assert.Len(t, change, 3)
1058
1059 // Make sure sequence numbers are monotonically increasing
1060 receivedSeq, ok := change[0].(float64)
1061 if ok {
1062 assert.True(t, receivedSeq > lastReceivedSeq)
1063 lastReceivedSeq = receivedSeq
1064 } else {
1065 nonIntegerSequenceReceived = true

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
CreateUserMethod · 0.95
SetUpTestLoggingFunction · 0.92
JSONUnmarshalFunction · 0.92
JSONMarshalFunction · 0.92
NewRestTesterFunction · 0.85
WaitWithTimeoutFunction · 0.85
DoneMethod · 0.80
newRequestMethod · 0.80
SendRevMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected