Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit 632af71

Browse files
committed
improve finish logic
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
1 parent 58614ad commit 632af71

File tree

3 files changed

+28
-29
lines changed

3 files changed

+28
-29
lines changed

testcase/write-stress/append.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"context"
1818
"encoding/base64"
1919
"math/rand"
20+
"sync"
2021

2122
"github.com/ngaut/log"
2223
"github.com/pingcap/errors"
@@ -39,25 +40,24 @@ func (c *appendClient) SetUp(ctx context.Context, nodes []cluster.Node, clientNo
3940
}
4041

4142
func (c *appendClient) Start(ctx context.Context, cfg interface{}, clientNodes []cluster.ClientNode) error {
42-
ctx2, cancel := context.WithCancel(ctx)
43-
defer cancel()
44-
45-
ch := make(chan error)
43+
var wg sync.WaitGroup
4644
for i := 0; i < c.concurrency; i++ {
45+
wg.Add(1)
4746
go func() {
48-
err := c.runClient(ctx2)
49-
log.Error(err)
50-
ch <- err
47+
defer wg.Done()
48+
for {
49+
select {
50+
case <-ctx.Done():
51+
return
52+
default:
53+
}
54+
err := c.runClient(ctx)
55+
log.Error(err)
56+
}
5157
}()
5258
}
5359

54-
for i := 0; i < c.concurrency; i++ {
55-
err := <-ch
56-
if err != nil {
57-
return err
58-
}
59-
}
60-
60+
wg.Wait()
6161
log.Info("everything is ok!")
6262
return nil
6363
}

testcase/write-stress/client.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,5 @@ func (c *baseClient) SetUp(ctx context.Context, _ []cluster.Node, clientNodes []
6464
}
6565

6666
func (c *baseClient) TearDown(ctx context.Context, nodes []cluster.ClientNode, idx int) error {
67-
util.MustExec(c.db, "drop table t")
6867
return nil
6968
}

testcase/write-stress/uniform.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"context"
1818
"encoding/base64"
1919
"math/rand"
20+
"sync"
2021

2122
"github.com/google/uuid"
2223
"github.com/ngaut/log"
@@ -41,25 +42,24 @@ func (c *uniformClient) SetUp(ctx context.Context, nodes []cluster.Node, clientN
4142

4243
// Start implements the core.StandardClientExtensions interface.
4344
func (c *uniformClient) Start(ctx context.Context, cfg interface{}, clientNodes []cluster.ClientNode) error {
44-
ctx2, cancel := context.WithCancel(ctx)
45-
defer cancel()
46-
47-
ch := make(chan error)
45+
var wg sync.WaitGroup
4846
for i := 0; i < c.concurrency; i++ {
47+
wg.Add(1)
4948
go func() {
50-
err := c.runClient(ctx2)
51-
log.Error(err)
52-
ch <- err
49+
defer wg.Done()
50+
for {
51+
select {
52+
case <-ctx.Done():
53+
return
54+
default:
55+
}
56+
err := c.runClient(ctx)
57+
log.Error(err)
58+
}
5359
}()
5460
}
5561

56-
for i := 0; i < c.concurrency; i++ {
57-
err := <-ch
58-
if err != nil {
59-
return err
60-
}
61-
}
62-
62+
wg.Wait()
6363
log.Info("everything is ok!")
6464
return nil
6565
}

0 commit comments

Comments
 (0)