update
All checks were successful
Build and Publish / BuildAndDeployAmd64 (push) Successful in 28s
Build and Publish / BuildAndDeploy (push) Successful in 2m32s

This commit is contained in:
matst80
2024-11-13 23:12:09 +01:00
parent 0a0fd1738c
commit 78abef7d73
4 changed files with 36 additions and 5 deletions

View File

@@ -18,6 +18,9 @@ type CartIdPayload struct {
}
func MakeCartInnerFrame(id CartId, payload []byte) []byte {
if payload == nil {
return id[:]
}
return append(id[:], payload...)
}

17
remote-grain_test.go Normal file
View File

@@ -0,0 +1,17 @@
package main
import "testing"
func TestCartIdsNullData(t *testing.T) {
data := MakeCartInnerFrame(ToCartId("kalle"), nil)
cart, err := GetCartFrame(data)
if err != nil {
t.Errorf("Error getting cart: %v", err)
}
if cart.Id.String() != "kalle" {
t.Errorf("Expected kalle, got %s", cart.Id)
}
if len(cart.Data) != 0 {
t.Errorf("Expected no data, got %v", cart.Data)
}
}

View File

@@ -366,12 +366,16 @@ func (p *SyncedPool) AddRemote(host string) {
if host == "" || hasHost {
return
}
// if host == "" || hasHost || host == p.Hostname {
// return
// }
client := NewConnection(fmt.Sprintf("%s:1338", host))
_, err := client.Call(Ping, nil)
r, err := client.Call(Ping, nil)
if err != nil {
log.Printf("Error connecting to remote %s: %s\n", host, err)
return
}
log.Printf("Connected to remote %s: %v\n", host, r)
remote := RemoteHost{
Connection: client,

View File

@@ -13,18 +13,25 @@ func TestConnection(t *testing.T) {
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")
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"))