mirror of
https://github.com/EchoVault/SugarDB.git
synced 2025-10-05 16:06:57 +08:00
Replaced all time.After instances to time.Ticker
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -373,14 +373,17 @@ func Test_Cluster(t *testing.T) {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
// 3. Check the delete count is equal to length of tests.
|
||||
if res.Integer() != len(tests) {
|
||||
t.Errorf("expected delete response to be %d, got %d", len(tests), res.Integer())
|
||||
}
|
||||
|
||||
<-time.After(200 * time.Millisecond) // Yield
|
||||
// Yield
|
||||
ticker.Reset(200 * time.Millisecond)
|
||||
<-ticker.C
|
||||
|
||||
// Check if the data is absent in quorum (majority of the cluster).
|
||||
// 4. Check if the data is absent in quorum (majority of the cluster).
|
||||
for i, test := range tests {
|
||||
count := 0
|
||||
for j := 0; j < len(nodes); j++ {
|
||||
@@ -399,7 +402,7 @@ func Test_Cluster(t *testing.T) {
|
||||
count += 1 // If the expected value is found, increment the count.
|
||||
}
|
||||
}
|
||||
// Fail if count is less than quorum.
|
||||
// 5. Fail if count is less than quorum.
|
||||
if count < quorum {
|
||||
t.Errorf("could not find value %s at key %s in cluster quorum", test.value, test.key)
|
||||
}
|
||||
@@ -461,7 +464,9 @@ func Test_Cluster(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
<-time.After(200 * time.Millisecond) // Yield to give key deletion time to take effect across cluster.
|
||||
// Yield to give key deletion time to take effect across cluster.
|
||||
ticker.Reset(200 * time.Millisecond)
|
||||
<-ticker.C
|
||||
|
||||
// Check if the data is absent in quorum (majority of the cluster).
|
||||
for i, test := range tests {
|
||||
@@ -557,8 +562,10 @@ func Test_Cluster(t *testing.T) {
|
||||
doneChan <- struct{}{}
|
||||
}()
|
||||
|
||||
ticker.Reset(5 * time.Second)
|
||||
|
||||
select {
|
||||
case <-time.After(5 * time.Second):
|
||||
case <-ticker.C:
|
||||
if forwardError != nil {
|
||||
t.Errorf("timeout error: %v\n", forwardError)
|
||||
}
|
||||
|
@@ -118,7 +118,12 @@ func Test_AOFEngine(t *testing.T) {
|
||||
state[command[1]] = internal.KeyData{Value: command[2], ExpireAt: time.Time{}}
|
||||
engine.QueueCommand(marshalRespCommand(command))
|
||||
}
|
||||
<-time.After(100 * time.Millisecond)
|
||||
ticker := time.NewTicker(100 * time.Millisecond)
|
||||
defer func() {
|
||||
ticker.Stop()
|
||||
}()
|
||||
|
||||
<-ticker.C
|
||||
|
||||
// Trigger log rewrite
|
||||
if err = engine.RewriteLog(); err != nil {
|
||||
@@ -136,7 +141,9 @@ func Test_AOFEngine(t *testing.T) {
|
||||
state[command[1]] = internal.KeyData{Value: command[2], ExpireAt: time.Time{}}
|
||||
engine.QueueCommand(marshalRespCommand(command))
|
||||
}
|
||||
<-time.After(100 * time.Millisecond)
|
||||
|
||||
ticker.Reset(100 * time.Millisecond)
|
||||
<-ticker.C
|
||||
|
||||
// Restore logs
|
||||
if err = engine.Restore(); err != nil {
|
||||
|
@@ -35,6 +35,10 @@ func marshalRespCommand(command []string) []byte {
|
||||
}
|
||||
|
||||
func Test_AppendStore(t *testing.T) {
|
||||
t.Cleanup(func() {
|
||||
_ = os.RemoveAll(path.Join(".", "testdata"))
|
||||
})
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
directory string
|
||||
@@ -133,14 +137,16 @@ func Test_AppendStore(t *testing.T) {
|
||||
done <- struct{}{}
|
||||
}()
|
||||
|
||||
ticker := time.NewTicker(200 * time.Millisecond)
|
||||
defer func() {
|
||||
ticker.Stop()
|
||||
}()
|
||||
|
||||
select {
|
||||
case <-done:
|
||||
_ = os.RemoveAll(test.directory)
|
||||
case <-time.After(200 * time.Millisecond):
|
||||
_ = os.RemoveAll(test.directory)
|
||||
case <-ticker.C:
|
||||
t.Error("timeout error")
|
||||
}
|
||||
}
|
||||
|
||||
_ = os.RemoveAll("./testdata")
|
||||
}
|
||||
|
@@ -31,10 +31,13 @@ func Test_CacheLRU(t *testing.T) {
|
||||
}
|
||||
|
||||
access := []string{"key3", "key4", "key1", "key2", "key5"}
|
||||
ticker := time.NewTicker(200 * time.Millisecond)
|
||||
for _, key := range access {
|
||||
cache.Update(key)
|
||||
<-time.After(1 * time.Millisecond)
|
||||
// Yield
|
||||
<-ticker.C
|
||||
}
|
||||
ticker.Stop()
|
||||
|
||||
for i := len(access) - 1; i >= 0; i-- {
|
||||
key := heap.Pop(&cache).(string)
|
||||
|
Reference in New Issue
Block a user