Files
go-cart-actor/synced-pool_test.go
matst80 7795fc9c39
All checks were successful
Build and Publish / BuildAndDeployAmd64 (push) Successful in 27s
Build and Publish / BuildAndDeploy (push) Successful in 2m20s
update status data
2024-11-13 23:39:28 +01:00

67 lines
1.4 KiB
Go

package main
import (
"log"
"testing"
"time"
messages "git.tornberg.me/go-cart-actor/proto"
)
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{},
Deliveries: make([]CartDelivery, 0),
TotalPrice: 0,
}, nil
})
hg, err := NewGrainHandler(localPool, ":1337")
if err != nil {
t.Errorf("Error creating handler: %v\n", err)
}
if hg == nil {
t.Errorf("Expected handler, got nil")
}
pool, err := NewSyncedPool(localPool, "127.0.0.1", nil)
if err != nil {
t.Errorf("Error creating pool: %v", err)
}
time.Sleep(400 * time.Millisecond)
pool.AddRemote("127.0.0.1")
go pool.Negotiate()
msg := Message{
Type: AddItemType,
//TimeStamp: time.Now().Unix(),
Content: &messages.AddItem{
Quantity: 1,
Price: 100,
Sku: "123",
Name: "Test",
Image: "Test",
},
}
data, err := pool.Process(ToCartId("kalle"), msg)
if err != nil {
t.Errorf("Error getting data: %v", err)
}
if data.StatusCode != 200 {
t.Errorf("Expected 200")
}
log.Println(data)
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")
}
}