Skip to content

Commit

Permalink
Prevent RunTestConcurrency from creating garbage clients (#793)
Browse files Browse the repository at this point in the history
Change `RunTestTreeConcurrency` in `tree_concurrency_test.go` not
to create and close clients in each test. This commit can solve the
performance degradation problem that occurs when vector clocks are
used.
  • Loading branch information
justiceHui authored Feb 14, 2024
1 parent a8f6bc2 commit 0987cbc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
19 changes: 10 additions & 9 deletions test/integration/tree_concurrency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,16 +207,17 @@ func (op editOperationType) run(t *testing.T, doc *document.Document, user int,
func RunTestTreeConcurrency(testDesc string, t *testing.T, initialState json.TreeNode, initialXML string,
rangesArr []twoRangesType, opArr1, opArr2 []operationInterface) {

clients := activeClients(t, 2)
c1, c2 := clients[0], clients[1]
defer deactivateAndCloseClients(t, clients)

ctx := context.Background()
d1 := document.New(helper.TestDocKey(t))
assert.NoError(t, c1.Attach(ctx, d1))
d2 := document.New(helper.TestDocKey(t))
assert.NoError(t, c2.Attach(ctx, d2))

runTest := func(ranges twoRangesType, op1, op2 operationInterface) testResult {
clients := activeClients(t, 2)
c1, c2 := clients[0], clients[1]
defer deactivateAndCloseClients(t, clients)

ctx := context.Background()
d1 := document.New(helper.TestDocKey(t))
assert.NoError(t, c1.Attach(ctx, d1))
d2 := document.New(helper.TestDocKey(t))
assert.NoError(t, c2.Attach(ctx, d2))

assert.NoError(t, d1.Update(func(root *json.Object, p *presence.Presence) error {
root.SetNewTree("t", &initialState)
Expand Down
4 changes: 2 additions & 2 deletions test/integration/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ func TestTree(t *testing.T) {
root.GetTree("t").EditBulk(3, 3, []*json.TreeNode{{
Type: "text",
Value: "c",
}, &json.TreeNode{
}, {
Type: "text",
Value: "d",
}}, 0)
Expand All @@ -451,7 +451,7 @@ func TestTree(t *testing.T) {
root.GetTree("t").EditBulk(4, 4, []*json.TreeNode{{
Type: "p",
Children: []json.TreeNode{{Type: "text", Value: "cd"}},
}, &json.TreeNode{
}, {
Type: "i",
Children: []json.TreeNode{{Type: "text", Value: "fg"}},
}}, 0)
Expand Down

0 comments on commit 0987cbc

Please sign in to comment.