mirror of
https://github.com/go-micro/go-micro.git
synced 2025-06-18 22:17:44 +02:00
improve the syncMap.Iterate test to make it 100% reproducible (#970)
* improve the syncMap.Iterate test to make it 100% reproducible * rename store/mocks/Store.go * rename mocks/store to mock/store
This commit is contained in:
@ -4,14 +4,13 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
store "github.com/micro/go-micro/store"
|
||||
mem_store "github.com/micro/go-micro/store/memory"
|
||||
"github.com/micro/go-micro/store"
|
||||
store_mock "github.com/micro/go-micro/store/mock"
|
||||
mem_lock "github.com/micro/go-micro/sync/lock/memory"
|
||||
"github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
func TestIterate(t *testing.T) {
|
||||
s1 := mem_store.NewStore()
|
||||
s2 := mem_store.NewStore()
|
||||
recA := &store.Record{
|
||||
Key: "A",
|
||||
Value: nil,
|
||||
@ -20,10 +19,12 @@ func TestIterate(t *testing.T) {
|
||||
Key: "B",
|
||||
Value: nil,
|
||||
}
|
||||
s1.Write(recA)
|
||||
s1.Write(recB)
|
||||
s2.Write(recB)
|
||||
s2.Write(recA)
|
||||
s1 := &store_mock.Store{}
|
||||
s2 := &store_mock.Store{}
|
||||
s1.On("List").Return([]*store.Record{recA, recB}, nil)
|
||||
s2.On("List").Return([]*store.Record{recB, recA}, nil)
|
||||
s1.On("Write", mock.Anything).Return(nil)
|
||||
s2.On("Write", mock.Anything).Return(nil)
|
||||
|
||||
f := func(key, val interface{}) error {
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
|
Reference in New Issue
Block a user