瀏覽代碼

Better error messages

Burke Libbey 12 年之前
父節點
當前提交
2bad7afe8f
共有 1 個文件被更改,包括 5 次插入5 次删除
  1. 5 5
      mockbroker.go

+ 5 - 5
mockbroker.go

@@ -26,7 +26,7 @@ type MockBroker struct {
 	expectations chan encoder
 	expectations chan encoder
 	listener     net.Listener
 	listener     net.Listener
 	t            *testing.T
 	t            *testing.T
-	expecting    bool
+	expecting    encoder
 }
 }
 
 
 func (b *MockBroker) BrokerID() int {
 func (b *MockBroker) BrokerID() int {
@@ -48,8 +48,8 @@ func (r rawExpectation) ResponseBytes() []byte {
 }
 }
 
 
 func (b *MockBroker) Close() {
 func (b *MockBroker) Close() {
-	if b.expecting {
-		b.t.Fatalf("Not all expectations were satisfied in mockBroker with ID=%d!", b.BrokerID())
+	if b.expecting != nil {
+		b.t.Fatalf("Not all expectations were satisfied in mockBroker with ID=%d! Still waiting on %#v", b.BrokerID(), b.expecting)
 	}
 	}
 	close(b.expectations)
 	close(b.expectations)
 	<-b.stopper
 	<-b.stopper
@@ -68,9 +68,9 @@ func (b *MockBroker) serverLoop() (ok bool) {
 	reqHeader := make([]byte, 4)
 	reqHeader := make([]byte, 4)
 	resHeader := make([]byte, 8)
 	resHeader := make([]byte, 8)
 	for expectation := range b.expectations {
 	for expectation := range b.expectations {
-		b.expecting = true
+		b.expecting = expectation
 		_, err = io.ReadFull(conn, reqHeader)
 		_, err = io.ReadFull(conn, reqHeader)
-		b.expecting = false
+		b.expecting = nil
 		if err != nil {
 		if err != nil {
 			return b.serverError(err, conn)
 			return b.serverError(err, conn)
 		}
 		}