Changed TestLink to test add and remove

gql_cataclysm
noah metz 2023-08-15 19:28:15 -06:00
parent f398c9659e
commit 4ce2a642c5
2 changed files with 43 additions and 3 deletions

@ -196,6 +196,9 @@ func (ext *LockableExt) HandleLinkSignal(log Logger, node *Node, source NodeID,
if exists == true { if exists == true {
msgs = msgs.Add(node.ID, node.Key, NewErrorSignal(signal.ID(), "already_requirement"), source) msgs = msgs.Add(node.ID, node.Key, NewErrorSignal(signal.ID(), "already_requirement"), source)
} else { } else {
if ext.Requirements == nil {
ext.Requirements = map[NodeID]ReqState{}
}
ext.Requirements[id] = Unlocked ext.Requirements[id] = Unlocked
msgs = msgs.Add(node.ID, node.Key, NewErrorSignal(signal.ID(), "req_added"), source) msgs = msgs.Add(node.ID, node.Key, NewErrorSignal(signal.ID(), "req_added"), source)
} }

@ -18,7 +18,7 @@ func lockableTestContext(t *testing.T, logs []string) *Context {
} }
func TestLink(t *testing.T) { func TestLink(t *testing.T) {
ctx := lockableTestContext(t, []string{"listener"}) ctx := lockableTestContext(t, []string{"lockable"})
l1_pub, l1_key, err := ed25519.GenerateKey(rand.Reader) l1_pub, l1_key, err := ed25519.GenerateKey(rand.Reader)
fatalErr(t, err) fatalErr(t, err)
@ -39,10 +39,20 @@ func TestLink(t *testing.T) {
l1_listener := NewListenerExt(10) l1_listener := NewListenerExt(10)
l1 := NewNode(ctx, l1_key, TestLockableType, 10, nil, l1 := NewNode(ctx, l1_key, TestLockableType, 10, nil,
l1_listener, l1_listener,
NewLockableExt([]NodeID{l2.ID}), NewLockableExt(nil),
) )
msgs := Messages{} msgs := Messages{}
msgs = msgs.Add(l1.ID, l1.Key, NewLinkSignal("add", l2.ID), l1.ID)
err = ctx.Send(msgs)
fatalErr(t, err)
_, err = WaitForSignal(l1_listener.Chan, time.Millisecond*10, ErrorSignalType, func(sig *ErrorSignal) bool {
return sig.Error == "req_added"
})
fatalErr(t, err)
msgs = Messages{}
s := NewBaseSignal("TEST", Down) s := NewBaseSignal("TEST", Down)
msgs = msgs.Add(l1.ID, l1.Key, &s, l1.ID) msgs = msgs.Add(l1.ID, l1.Key, &s, l1.ID)
err = ctx.Send(msgs) err = ctx.Send(msgs)
@ -57,9 +67,36 @@ func TestLink(t *testing.T) {
return sig.ID() == s.ID() return sig.ID() == s.ID()
}) })
fatalErr(t, err) fatalErr(t, err)
msgs = Messages{}
msgs = msgs.Add(l1.ID, l1.Key, NewLinkSignal("remove", l2.ID), l1.ID)
err = ctx.Send(msgs)
fatalErr(t, err)
_, err = WaitForSignal(l1_listener.Chan, time.Millisecond*10, ErrorSignalType, func(sig *ErrorSignal) bool {
return sig.Error == "req_removed"
})
fatalErr(t, err)
msgs = Messages{}
s = NewBaseSignal("TEST", Down)
msgs = msgs.Add(l1.ID, l1.Key, &s, l1.ID)
err = ctx.Send(msgs)
fatalErr(t, err)
_, err = WaitForSignal(l1_listener.Chan, time.Millisecond*10, "TEST", func(sig *BaseSignal) bool {
return sig.ID() == s.ID()
})
fatalErr(t, err)
select {
case <- l2_listener.Chan:
t.Fatal("Recevied message on l2 after removing link")
default:
}
} }
func TestLink10K(t *testing.T) { func Test10KLink(t *testing.T) {
ctx := lockableTestContext(t, []string{"test"}) ctx := lockableTestContext(t, []string{"test"})
l_pub, listener_key, err := ed25519.GenerateKey(rand.Reader) l_pub, listener_key, err := ed25519.GenerateKey(rand.Reader)