示例#1
0
func runWrite(t *testing.T, num int, c zmqchan.ChanSocket) {
	tx := 0
	rx := 0
	srcMsg := [][]byte{[]byte("Hello"), []byte("World")}
	txchan := c.GetTxChan()
	for {
		select {
		case msg, ok := <-c.GetRxChan():
			if !ok {
				t.Fatal("Cannot read from main channel")
			}
			rx++
			log.Printf("MAIN: got message %d", rx)
			if !msgEqual(msg, srcMsg) {
				t.Fatal("Messages do not match")
			}
			if rx >= num {
				log.Println("MAIN: done")
				return
			}
		case txchan <- srcMsg:
			log.Println("MAIN: sent message")
			tx++
			if tx >= num {
				txchan = nil
			}
		case <-time.After(1 * time.Second):
			t.Fatal("Timeout in runWrite")
		}
	}
}
示例#2
0
func runEcho(t *testing.T, num int, c zmqchan.ChanSocket) {
	for {
		select {
		case msg, ok := <-c.GetRxChan():
			if !ok {
				t.Fatal("Cannot read from echo channel")
			}
			log.Println("ECHO: got message")
			c.GetTxChan() <- msg
			log.Println("ECHO: sent message")
			num--
			if num <= 0 {
				log.Println("ECHO: done")
				return
			}
		case <-time.After(1 * time.Second):
			t.Fatal("Timeout in runEcho")
		}
	}
}