@@ -11,8 +11,6 @@ import (
1111 "sync/atomic"
1212 "testing"
1313
14- "fmt"
15-
1614 "time"
1715
1816 "reflect"
@@ -35,7 +33,7 @@ func TestDeadlock(t *testing.T) {
3533 return
3634 }
3735
38- fmt . Printf ("EventHub Concurrency test\n " )
36+ t . Log ("EventHub Concurrency test" )
3937
4038 client := clientFactory .clients [0 ]
4139 if client == nil {
@@ -101,13 +99,13 @@ func TestDeadlock(t *testing.T) {
10199 if txCompletion .numDone () != eventsSent {
102100 t .Errorf ("Sent %d Tx events but received %d - could indicate a deadlock" , eventsSent , txCompletion .numDone ())
103101 } else {
104- fmt . Printf ("Received all %d TX events. \n " , txCompletion .numDone ())
102+ t . Logf ("Received all %d TX events" , txCompletion .numDone ())
105103 }
106104
107105 if ccCompletion .numDone () != eventsSent {
108106 t .Errorf ("Sent %d CC events but received %d - could indicate a deadlock" , eventsSent , ccCompletion .numDone ())
109107 } else {
110- fmt . Printf ("Received all %d CC events. \n " , ccCompletion .numDone ())
108+ t . Logf ("Received all %d CC events" , ccCompletion .numDone ())
111109 }
112110}
113111
@@ -120,7 +118,7 @@ func TestChaincodeEvent(t *testing.T) {
120118 return
121119 }
122120
123- fmt . Printf ("EventHub Chaincode event test\n " )
121+ t . Log ("EventHub Chaincode event test" )
124122
125123 client := clientFactory .clients [0 ]
126124 if client == nil {
@@ -305,20 +303,22 @@ func TestRegisterBlockEvent(t *testing.T) {
305303 t .Fatalf ("Registered callback is not txCallback" )
306304 }
307305
308- eventHub .RegisterBlockEvent (testCallback )
306+ w := & callbackWrapper {t }
307+
308+ eventHub .RegisterBlockEvent (w .testCallback )
309309
310310 if len (eventHub .blockRegistrants ) != 2 {
311311 t .Fatalf ("Failed to add test callback for block event" )
312312 }
313313
314- f1 = reflect .ValueOf (testCallback )
314+ f1 = reflect .ValueOf (w . testCallback )
315315 f2 = reflect .ValueOf (eventHub .blockRegistrants [1 ])
316316
317317 if f1 .Pointer () != f2 .Pointer () {
318318 t .Fatalf ("Registered callback is not testCallback" )
319319 }
320320
321- eventHub .UnregisterBlockEvent (testCallback )
321+ eventHub .UnregisterBlockEvent (w . testCallback )
322322
323323 if len (eventHub .interestedEvents ) != 1 || len (eventHub .blockRegistrants ) != 1 {
324324 t .Fatalf ("Failed to unregister testCallback" )
@@ -332,9 +332,13 @@ func TestRegisterBlockEvent(t *testing.T) {
332332
333333}
334334
335+ type callbackWrapper struct {
336+ t * testing.T
337+ }
338+
335339// private test callback to be executed on block event
336- func testCallback (block * common.Block ) {
337- fmt . Println ("testCallback called on block" )
340+ func ( w * callbackWrapper ) testCallback (block * common.Block ) {
341+ w . t . Log ("testCallback called on block" )
338342}
339343
340344func TestRegisterChaincodeEvent (t * testing.T ) {
@@ -348,7 +352,9 @@ func TestRegisterChaincodeEvent(t *testing.T) {
348352 t .Fatalf ("Transaction callback should be registered by default" )
349353 }
350354
351- cbe := eventHub .RegisterChaincodeEvent ("testCC" , "eventID" , testChaincodeCallback )
355+ w := & callbackWrapper {t }
356+
357+ cbe := eventHub .RegisterChaincodeEvent ("testCC" , "eventID" , w .testChaincodeCallback )
352358
353359 if len (eventHub .interestedEvents ) != 2 {
354360 t .Fatalf ("Failed to register interest for CC event" )
@@ -379,8 +385,8 @@ func TestRegisterChaincodeEvent(t *testing.T) {
379385}
380386
381387// private test callback to be executed on chaincode event
382- func testChaincodeCallback (ce * fab.ChaincodeEvent ) {
383- fmt . Printf ("Received CC event: %v\n " , ce )
388+ func ( w * callbackWrapper ) testChaincodeCallback (ce * fab.ChaincodeEvent ) {
389+ w . t . Logf ("Received CC event: %v" , ce )
384390}
385391
386392func TestDisconnect (t * testing.T ) {
0 commit comments