update
This commit is contained in:
@@ -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
17
remote-grain_test.go
Normal 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)
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -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"))
|
||||
|
||||
Reference in New Issue
Block a user