github.com/haraldrudell/parl@v0.4.176/g0/g0debug/thread-logger_test.go (about) 1 /* 2 © 2022–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/) 3 ISC License 4 */ 5 6 package g0debug 7 8 import ( 9 "context" 10 "testing" 11 12 "github.com/haraldrudell/parl" 13 "github.com/haraldrudell/parl/g0" 14 ) 15 16 func ExitingGoroutine(g parl.Go) { 17 g.Done(nil) 18 } 19 20 func ReadErrorChannelToEnd(ch <-chan parl.GoError, t *testing.T) { 21 } 22 23 func TestThreadLogger(t *testing.T) { 24 25 // goGroup being logged 26 var goGroup parl.GoGroup = g0.NewGoGroup(context.Background()) 27 28 // waitgroup for threadLogger end 29 var wg = NewThreadLogger(goGroup).Log() 30 31 // launch a quickly terminating goroutine 32 // - this will cause goGroup to terminate 33 go ExitingGoroutine(goGroup.Go()) 34 35 // read error channel to end 36 for { 37 e, ok := <-goGroup.Ch() 38 if !ok { 39 break // error channel closed 40 } 41 var err = e.Err() 42 if err != nil { 43 t.Errorf("goGroup err: %s", e) 44 } 45 } 46 47 t.Log("wg.Wait…") 48 wg.Wait() 49 t.Log("wg.Wait complete") 50 }