1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-09 09:35:03 +09:00

GO-3170: add test for pick function pick and remove p2p status from anysync

Signed-off-by: AnastasiaShemyakinskaya <shem98a@mail.ru>
This commit is contained in:
AnastasiaShemyakinskaya 2024-05-30 23:05:06 +02:00
parent a2b8442749
commit 68c853f2ce
No known key found for this signature in database
GPG key ID: CCD60ED83B103281
4 changed files with 34 additions and 15 deletions

View file

@ -133,5 +133,5 @@ func (p *pool) pick(ctx context.Context, source ocache.OCache, id string) (peer.
if !pr.IsClosed() {
return pr, nil
}
return nil, fmt.Errorf("failed to pick connection with peer: peer not founc")
return nil, fmt.Errorf("failed to pick connection with peer: peer not found")
}

View file

@ -153,7 +153,40 @@ func TestPool_AddPeer(t *testing.T) {
assert.Truef(t, false, "peer not closed")
}
})
}
func TestPool_Pick(t *testing.T) {
t.Run("not exist", func(t *testing.T) {
fx := newFixture(t)
defer fx.Finish()
p, err := fx.Pick(ctx, "1")
assert.Nil(t, p)
assert.NotNil(t, err)
})
t.Run("success", func(t *testing.T) {
fx := newFixture(t)
defer fx.Finish()
p1 := newTestPeer("p1")
require.NoError(t, fx.AddPeer(ctx, p1))
p, err := fx.Pick(ctx, "p1")
assert.NotNil(t, p)
assert.Equal(t, p1, p)
assert.Nil(t, err)
})
t.Run("peer is closed", func(t *testing.T) {
fx := newFixture(t)
defer fx.Finish()
p1 := newTestPeer("p1")
require.NoError(t, fx.AddPeer(ctx, p1))
require.NoError(t, p1.Close())
p, err := fx.Pick(ctx, "p1")
assert.Nil(t, p)
assert.NotNil(t, err)
})
}
func newFixture(t *testing.T) *fixture {