github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/worker/logsender/logsendertest/logsendertest.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package logsendertest 5 6 import ( 7 "reflect" 8 9 gc "gopkg.in/check.v1" 10 11 "github.com/juju/juju/testing" 12 "github.com/juju/juju/worker/logsender" 13 ) 14 15 // ExpectLogStats waits for the buffered log writer's 16 // statistics to match the expected value. This is 17 // provided because statistics are updated after 18 // log messages are handed off to the sink, and so 19 // tests must cater for the gap or races will occur. 20 func ExpectLogStats(c *gc.C, writer *logsender.BufferedLogWriter, expect logsender.LogStats) { 21 var stats logsender.LogStats 22 for a := testing.LongAttempt.Start(); a.Next(); { 23 stats = writer.Stats() 24 if reflect.DeepEqual(stats, expect) { 25 return 26 } 27 } 28 c.Errorf("timed out waiting for statistics: got %+v, expected %+v", stats, expect) 29 }