1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-07 21:47:02 +09:00

WIP sync integration test

This commit is contained in:
mcrakhman 2024-06-18 22:02:36 +02:00
parent d1986a4115
commit ee53e956a8
No known key found for this signature in database
GPG key ID: DED12CFEF5B8396B
2 changed files with 24 additions and 6 deletions

View file

@ -229,7 +229,7 @@ func (s *spaceProcess) Init(a *app.App) (err error) {
s.manager = a.MustComponent(treemanager.CName).(*mockTreeManager)
s.spaceServer = a.MustComponent(RpcName).(*RpcServer)
s.accountService = a.MustComponent(accountservice.CName).(accountservice.Service)
s.periodicCall = periodicsync.NewPeriodicSyncDuration(5*time.Second, 0, s.update, log)
s.periodicCall = periodicsync.NewPeriodicSyncDuration(50*time.Millisecond, 0, s.update, log)
return
}
@ -253,7 +253,7 @@ func (s *spaceProcess) update(ctx context.Context) error {
return err
}
var tr objecttree.ObjectTree
newDoc := rand.Int()%10 == 0
newDoc := rand.Int()%20 == 0
snapshot := rand.Int()%10 == 0
allTrees := sp.StoredIds()
if newDoc || len(allTrees) == 0 {

View file

@ -272,7 +272,7 @@ func (m *mockConfig) Name() (name string) {
func (m *mockConfig) GetSpace() config.Config {
return config.Config{
GCTTL: 60,
SyncPeriod: 20,
SyncPeriod: 5,
KeepTreeDataInMemory: true,
}
}
@ -584,6 +584,7 @@ type spaceFixture struct {
treeManager *mockTreeManager
pool *mockPool
spaceService SpaceService
process *spaceProcess
cancelFunc context.CancelFunc
}
@ -634,6 +635,7 @@ func newFixtureWithData(t *testing.T, spaceId string, keys *accountdata.AccountK
treeManager: newMockTreeManager(spaceId),
pool: &mockPool{},
spaceService: New(),
process: newSpaceProcess(spaceId),
}
fx.app.Register(fx.account).
Register(fx.config).
@ -650,7 +652,7 @@ func newFixtureWithData(t *testing.T, spaceId string, keys *accountdata.AccountK
Register(fx.treeManager).
Register(fx.spaceService).
Register(NewRpcServer()).
Register(newSpaceProcess(spaceId))
Register(fx.process)
err := fx.app.Start(ctx)
if err != nil {
fx.cancelFunc()
@ -737,8 +739,24 @@ func newMultiPeerFixture(t *testing.T, peerNum int) *multiPeerFixture {
return &multiPeerFixture{peerFixtures: peerFixtures}
}
func Test(t *testing.T) {
func Test_Sync(t *testing.T) {
mpFixture := newMultiPeerFixture(t, 3)
time.Sleep(100 * time.Second)
time.Sleep(5 * time.Second)
for _, fx := range mpFixture.peerFixtures {
err := fx.process.Close(context.Background())
require.NoError(t, err)
}
time.Sleep(5 * time.Second)
var hashes []string
for _, fx := range mpFixture.peerFixtures {
sp, err := fx.app.MustComponent(RpcName).(*RpcServer).GetSpace(context.Background(), fx.process.spaceId)
require.NoError(t, err)
spaceHash, err := sp.Storage().ReadSpaceHash()
require.NoError(t, err)
hashes = append(hashes, spaceHash)
}
for i := 1; i < len(hashes); i++ {
require.Equal(t, hashes[0], hashes[i])
}
mpFixture.Close()
}