Files
go-cart-actor/synced-pool_test.go
matst80 c5bc17c44d
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 1m52s
update stuff
2024-11-10 23:05:24 +01:00

46 lines
1018 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, "localhost", nil)
if err != nil {
t.Errorf("Error creating pool: %v", err)
}
err = pool.AddRemote("localhost")
if err != nil {
t.Errorf("Error adding remote: %v", err)
}
allHosts, err := pool.Negotiate([]string{"kalle", "pelle"})
if err != nil {
t.Errorf("Error negotiating: %v", err)
}
if len(allHosts) != 0 {
t.Errorf("Expected 0 host, (host should be known) got %d", len(allHosts))
}
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)
}