@@ -27,21 +27,21 @@ import (
2727 "github.com/tikv/pd/pkg/election"
2828)
2929
30- type MokElection struct {}
30+ type MockElection struct {}
3131
32- func (* MokElection ) ID () uint64 { return 0 }
33- func (* MokElection ) Name () string { return "" }
34- func (* MokElection ) MemberValue () string { return "" }
35- func (* MokElection ) Client () * clientv3.Client { return nil }
36- func (* MokElection ) IsServing () bool { return true }
37- func (* MokElection ) PromoteSelf () {}
38- func (* MokElection ) Campaign (_ context.Context , _ int64 ) error {
32+ func (* MockElection ) ID () uint64 { return 0 }
33+ func (* MockElection ) Name () string { return "" }
34+ func (* MockElection ) MemberValue () string { return "" }
35+ func (* MockElection ) Client () * clientv3.Client { return nil }
36+ func (* MockElection ) IsServing () bool { return true }
37+ func (* MockElection ) PromoteSelf () {}
38+ func (* MockElection ) Campaign (_ context.Context , _ int64 ) error {
3939 return nil
4040}
41- func (* MokElection ) Resign () {}
42- func (* MokElection ) GetServingUrls () []string { return nil }
43- func (* MokElection ) GetElectionPath () string { return "" }
44- func (* MokElection ) GetLeadership () * election.Leadership { return nil }
41+ func (* MockElection ) Resign () {}
42+ func (* MockElection ) GetServingUrls () []string { return nil }
43+ func (* MockElection ) GetElectionPath () string { return "" }
44+ func (* MockElection ) GetLeadership () * election.Leadership { return nil }
4545
4646func TestGenerateTSO (t * testing.T ) {
4747 re := require .New (t )
@@ -57,7 +57,7 @@ func TestGenerateTSO(t *testing.T) {
5757 updatePhysicalInterval : 5 * time .Second ,
5858 maxResetTSGap : func () time.Duration { return time .Hour },
5959 metrics : newTSOMetrics ("test" ),
60- member : & MokElection {},
60+ member : & MockElection {},
6161 }
6262
6363 // update physical time interval failed due to reach the lastSavedTime, it needs to save storage first, but this behavior is not allowed.
@@ -86,20 +86,20 @@ func TestCurrentGetTSO(t *testing.T) {
8686 updatePhysicalInterval : 5 * time .Second ,
8787 maxResetTSGap : func () time.Duration { return time .Hour },
8888 metrics : newTSOMetrics ("test" ),
89- member : & MokElection {},
89+ member : & MockElection {},
9090 }
9191
9292 runDuration := 5 * time .Second
9393 timestampOracle .lastSavedTime .Store (current .Add (runDuration ))
9494 runCtx , runCancel := context .WithTimeout (ctx , runDuration - time .Second )
9595 defer runCancel ()
9696 wg := sync.WaitGroup {}
97- wg .Add (100 )
97+ wg .Add (10 )
9898 changes := atomic.Int32 {}
9999 totalTso := atomic.Int32 {}
100- for i := range 100 {
100+ for i := range 10 {
101101 go func (i int ) {
102- physical := timestampOracle .tsoMux . physical
102+ pre , _ := timestampOracle .getTSO ()
103103 defer wg .Done ()
104104 for {
105105 select {
@@ -110,9 +110,10 @@ func TestCurrentGetTSO(t *testing.T) {
110110 totalTso .Add (1 )
111111 re .NoError (err )
112112 if i == 0 {
113- if physical != timestampOracle .tsoMux .physical {
113+ physical , _ := timestampOracle .getTSO ()
114+ if pre != physical {
114115 changes .Add (1 )
115- physical = timestampOracle . tsoMux . physical
116+ pre = physical
116117 }
117118 }
118119 }
0 commit comments