-
Notifications
You must be signed in to change notification settings - Fork 139
/
Copy pathchanges_request_plus_test.go
63 lines (51 loc) · 2.08 KB
/
changes_request_plus_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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright 2023-Present Couchbase, Inc.
//
// Use of this software is governed by the Business Source License included
// in the file licenses/BSL-Couchbase.txt. As of the Change Date specified
// in that file, in accordance with the Business Source License, use of this
// software will be governed by the Apache License, Version 2.0, included in
// the file licenses/APL2.txt.
package rest
import (
"fmt"
"net/http"
"testing"
"github.com/couchbase/sync_gateway/base"
"github.com/couchbase/sync_gateway/channels"
"github.com/couchbase/sync_gateway/db"
"github.com/stretchr/testify/require"
)
// TestRequirePlusSkippedSequence makes sure that a final skipped sequence in a request_plus request will not hang the request
func TestRequestPlusSkippedSequence(t *testing.T) {
defer db.SuspendSequenceBatching()()
restTesterConfig := RestTesterConfig{SyncFn: channels.DocChannelsSyncFunction}
// JWT claim based grants do not support named collections
rt := NewRestTester(t, &restTesterConfig)
defer rt.Close()
const (
username = "alice"
channel = "foo"
)
rt.CreateUser(username, []string{channel})
// add a single document for the user
resp := rt.SendAdminRequest(http.MethodPut, "/{{.keyspace}}/doc1", fmt.Sprintf(`{"channels":"%s"}`, channel))
RequireStatus(t, resp, http.StatusCreated)
docSeq := rt.GetDocumentSequence("doc1")
rt.WaitForPendingChanges()
// add an unused sequence
unusedSeq, err := db.AllocateTestSequence(rt.GetDatabase())
require.NoError(t, err)
caughtUpCount := rt.GetDatabase().DbStats.CBLReplicationPull().NumPullReplCaughtUp.Value()
requestFinished := make(chan struct{})
// make sure this request doesn't hang
go func() {
defer close(requestFinished)
changes := rt.GetChanges(fmt.Sprintf("/{{.keyspace}}/_changes?since=%d&request_plus=true", docSeq), username)
require.Len(t, changes.Results, 0)
}()
require.NoError(t, rt.GetDatabase().WaitForCaughtUp(caughtUpCount+1))
// the request should finish once the sequence is released
err = db.ReleaseTestSequence(base.TestCtx(t), rt.GetDatabase(), unusedSeq)
require.NoError(t, err)
<-requestFinished
}