Commit 2510d03b authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 2bfd266f
...@@ -39,6 +39,8 @@ import ( ...@@ -39,6 +39,8 @@ import (
"fmt" "fmt"
) )
var _ = fmt.Print
// XXX dup from connection_test // XXX dup from connection_test
func xwait(w interface { Wait() error }) { func xwait(w interface { Wait() error }) {
err := w.Wait() err := w.Wait()
...@@ -62,10 +64,9 @@ type traceMsg struct { ...@@ -62,10 +64,9 @@ type traceMsg struct {
// TraceChecker synchronously collects and checks tracing events // TraceChecker synchronously collects and checks tracing events
// it collects events from several sources and sends them all into one channel // it collects events from several sources and sends them all into one channel
// for each event the goroutine which produced it will wait for ack before continue // for each event the goroutine which produced it will wait for ack before continue
// XXX more text XXX naming -> verifier?
type TraceChecker struct { type TraceChecker struct {
t *testing.T t *testing.T
msgch chan *traceMsg // XXX or chan traceMsg (no ptr) ? msgch chan *traceMsg // XXX naming -> tracech ?
} }
func NewTraceChecker(t *testing.T) *TraceChecker { func NewTraceChecker(t *testing.T) *TraceChecker {
...@@ -74,26 +75,29 @@ func NewTraceChecker(t *testing.T) *TraceChecker { ...@@ -74,26 +75,29 @@ func NewTraceChecker(t *testing.T) *TraceChecker {
// get1 gets 1 event in place and checks it has expected type // get1 gets 1 event in place and checks it has expected type
func (tc *TraceChecker) xget1(eventp interface{}) *traceMsg { func (tc *TraceChecker) xget1(eventp interface{}) *traceMsg {
println("xget1: entry") tc.t.Helper()
//println("xget1: entry")
msg := <-tc.msgch msg := <-tc.msgch
println("xget1: msg", msg) //println("xget1: msg", msg)
revp := reflect.ValueOf(eventp) reventp := reflect.ValueOf(eventp)
if revp.Type().Elem() != reflect.TypeOf(msg.event) { if reventp.Type().Elem() != reflect.TypeOf(msg.event) {
tc.t.Fatalf("expected %s; got %#v", revp.Elem().Type(), msg.event) tc.t.Fatalf("expected %s; got %#v", reventp.Elem().Type(), msg.event)
} }
// TODO *event = msg.event
// *eventp = msg.event
reventp.Elem().Set(reflect.ValueOf(msg.event))
return msg return msg
} }
// trace1 sends message with one tracing event to consumer // trace1 sends message with one tracing event to consumer
func (tc *TraceChecker) trace1(event interface{}) { func (tc *TraceChecker) trace1(event interface{}) {
ack := make(chan struct{}) ack := make(chan struct{})
fmt.Printf("I: %v ...", event) //fmt.Printf("I: %#v ...", event)
println("zzz")
//panic(0)
tc.msgch <- &traceMsg{event, ack} tc.msgch <- &traceMsg{event, ack}
<-ack <-ack
fmt.Printf(" ok\n") //fmt.Printf(" ok\n")
} }
func (tc *TraceChecker) TraceNetDial(ev *xnet.TraceDial) { tc.trace1(ev) } func (tc *TraceChecker) TraceNetDial(ev *xnet.TraceDial) { tc.trace1(ev) }
...@@ -104,6 +108,8 @@ func (tc *TraceChecker) TraceNetTx(ev *xnet.TraceTx) { tc.trace1(ev) } ...@@ -104,6 +108,8 @@ func (tc *TraceChecker) TraceNetTx(ev *xnet.TraceTx) { tc.trace1(ev) }
// Expect instruct checker to expect next event to be ... // Expect instruct checker to expect next event to be ...
// XXX // XXX
func (tc *TraceChecker) ExpectNetDial(dst string) { func (tc *TraceChecker) ExpectNetDial(dst string) {
tc.t.Helper()
var ev *xnet.TraceDial var ev *xnet.TraceDial
msg := tc.xget1(&ev) msg := tc.xget1(&ev)
...@@ -115,6 +121,8 @@ func (tc *TraceChecker) ExpectNetDial(dst string) { ...@@ -115,6 +121,8 @@ func (tc *TraceChecker) ExpectNetDial(dst string) {
} }
func (tc *TraceChecker) ExpectNetListen(laddr string) { func (tc *TraceChecker) ExpectNetListen(laddr string) {
tc.t.Helper()
var ev *xnet.TraceListen var ev *xnet.TraceListen
msg := tc.xget1(&ev) msg := tc.xget1(&ev)
...@@ -122,11 +130,12 @@ func (tc *TraceChecker) ExpectNetListen(laddr string) { ...@@ -122,11 +130,12 @@ func (tc *TraceChecker) ExpectNetListen(laddr string) {
tc.t.Fatalf("net listen: have %v; want %v", ev.Laddr, laddr) tc.t.Fatalf("net listen: have %v; want %v", ev.Laddr, laddr)
} }
println("listen: ok")
close(msg.ack) close(msg.ack)
} }
func (tc *TraceChecker) ExpectNetTx(src, dst string, pkt string) { func (tc *TraceChecker) ExpectNetTx(src, dst string, pkt string) {
tc.t.Helper()
var ev *xnet.TraceTx var ev *xnet.TraceTx
msg := tc.xget1(&ev) msg := tc.xget1(&ev)
...@@ -161,11 +170,8 @@ func TestMasterStorage(t *testing.T) { ...@@ -161,11 +170,8 @@ func TestMasterStorage(t *testing.T) {
_ = err // XXX _ = err // XXX
}) })
println("222")
// expect: // expect:
//tc.ExpectNetListen("0") tc.ExpectNetListen("0")
tc.ExpectNetDial("0")
println("333")
// M.clusterState <- RECOVERY // M.clusterState <- RECOVERY
// M.nodeTab <- Node(M) // M.nodeTab <- Node(M)
...@@ -179,10 +185,15 @@ func TestMasterStorage(t *testing.T) { ...@@ -179,10 +185,15 @@ func TestMasterStorage(t *testing.T) {
}) })
// expect: // expect:
// M <- S .? RequestIdentification{...} + TODO test ID rejects tc.ExpectNetListen("1")
tc.ExpectNetDial("0")
tc.ExpectNetTx("2c", "2s", "\x00\x00\x00\x01") // handshake tc.ExpectNetTx("2c", "2s", "\x00\x00\x00\x01") // handshake
tc.ExpectNetTx("2s", "2c", "\x00\x00\x00\x01") tc.ExpectNetTx("2s", "2c", "\x00\x00\x00\x01")
// XXX temp
return
// M <- S .? RequestIdentification{...} + TODO test ID rejects
// M -> S .? AcceptIdentification{...} // M -> S .? AcceptIdentification{...}
// M.nodeTab <- Node(S) XXX order can be racy? // M.nodeTab <- Node(S) XXX order can be racy?
// S.nodeTab <- Node(M) XXX order can be racy? // S.nodeTab <- Node(M) XXX order can be racy?
......
...@@ -47,6 +47,7 @@ type Tracer interface { ...@@ -47,6 +47,7 @@ type Tracer interface {
// TraceDial is event corresponding to network dialing // TraceDial is event corresponding to network dialing
type TraceDial struct { type TraceDial struct {
// XXX also put Src here somehow ?
Dst string Dst string
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment