From 0987cbc0964c049bc38b3707750cea02cabd75b5 Mon Sep 17 00:00:00 2001 From: Jeounghui Nah Date: Wed, 14 Feb 2024 21:16:23 +0900 Subject: [PATCH] Prevent RunTestConcurrency from creating garbage clients (#793) 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. --- test/integration/tree_concurrency_test.go | 19 ++++++++++--------- test/integration/tree_test.go | 4 ++-- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/test/integration/tree_concurrency_test.go b/test/integration/tree_concurrency_test.go index 09c0a55b5..4c3a60534 100644 --- a/test/integration/tree_concurrency_test.go +++ b/test/integration/tree_concurrency_test.go @@ -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) diff --git a/test/integration/tree_test.go b/test/integration/tree_test.go index 5afb68c8d..b9726058b 100644 --- a/test/integration/tree_test.go +++ b/test/integration/tree_test.go @@ -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) @@ -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)