1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-11 18:20:28 +09:00

Add fixtures for testing

This commit is contained in:
mcrakhman 2024-06-15 21:51:50 +02:00
parent 4efac4a239
commit acc78e7080
No known key found for this signature in database
GPG key ID: DED12CFEF5B8396B
12 changed files with 257 additions and 34 deletions

View file

@ -33,6 +33,10 @@ type peerIdSettable interface {
SetPeerId(peerId string)
}
func New() syncdeps.SyncHandler {
return &objectSync{}
}
func (o *objectSync) Init(a *app.App) (err error) {
o.manager = a.MustComponent(treemanager.CName).(treemanager.TreeManager)
return

View file

@ -20,12 +20,15 @@ const CName = "common.commonspace.sync"
var log = logger.NewNamed("sync")
var ErrUnexpectedMessage = errors.New("unexpected message")
type SyncService interface {
app.Component
BroadcastMessage(ctx context.Context, msg drpc.Message) error
HandleStreamRequest(ctx context.Context, req syncdeps.Request, stream drpc.Stream) error
SendRequest(ctx context.Context, rq syncdeps.Request, collector syncdeps.ResponseCollector) error
QueueRequest(ctx context.Context, rq syncdeps.Request) error
CloseReceiveQueue(id string) error
}
type syncService struct {
@ -116,13 +119,17 @@ func (s *syncService) NewReadMessage() drpc.Message {
}
func (s *syncService) HandleMessage(ctx context.Context, peerId string, msg drpc.Message) error {
// TODO: make this queue per object and add closing of the individual queues
err := s.receiveQueue.Add(ctx, peerId, msgCtx{
idMsg, ok := msg.(syncdeps.Message)
if !ok {
return ErrUnexpectedMessage
}
objectId := idMsg.ObjectId()
err := s.receiveQueue.Add(ctx, objectId, msgCtx{
ctx: ctx,
Message: msg,
})
if errors.Is(err, mb.ErrOverflowed) {
log.Info("queue overflowed", zap.String("peerId", peerId))
log.Info("queue overflowed", zap.String("objectId", objectId))
return nil
}
return err
@ -139,3 +146,7 @@ func (s *syncService) SendRequest(ctx context.Context, rq syncdeps.Request, coll
func (s *syncService) HandleStreamRequest(ctx context.Context, req syncdeps.Request, stream drpc.Stream) error {
return s.manager.HandleStreamRequest(ctx, req, stream)
}
func (s *syncService) CloseReceiveQueue(id string) error {
return s.receiveQueue.CloseThread(id)
}

View file

@ -0,0 +1,5 @@
package syncdeps
type Message interface {
ObjectId() string
}

View file

@ -20,7 +20,7 @@ func (c *Config) Name() (name string) {
return "config"
}
func (c *Config) GetConfig() streampool.StreamConfig {
func (c *Config) GetStreamConfig() streampool.StreamConfig {
return streampool.StreamConfig{
SendQueueSize: 100,
DialQueueWorkers: 100,