Files
go-cart-actor/synced-pool_test.go
matst80 3615d2d7d1
All checks were successful
Build and Publish / BuildAndDeployAmd64 (push) Successful in 28s
Build and Publish / BuildAndDeploy (push) Successful in 2m23s
slaskit
2024-11-13 08:58:40 +01:00

46 lines
973 B
Go

package main
import (
"testing"
"time"
)
func TestConnection(t *testing.T) {
// TestConnection tests the connection to the server
localPool := NewGrainLocalPool(100, time.Minute, func(id CartId) (*CartGrain, error) {
return &CartGrain{
Id: id,
storageMessages: []Message{},
Items: []*CartItem{},
TotalPrice: 0,
}, nil
})
pool, err := NewSyncedPool(localPool, "127.0.0.1", nil)
if err != nil {
t.Errorf("Error creating pool: %v", err)
}
err = pool.AddRemote("127.0.0.1")
if err != nil {
t.Errorf("Error adding remote: %v", err)
}
go pool.Negotiate()
data, err := pool.Get(ToCartId("kalle"))
if err != nil {
t.Errorf("Error getting data: %v", err)
}
if data == nil {
t.Errorf("Expected data, got nil")
}
time.Sleep(2 * time.Millisecond)
data, err = pool.Get(ToCartId("kalle"))
if err != nil {
t.Errorf("Error getting data: %v", err)
}
if data == nil {
t.Errorf("Expected data, got nil")
}
}