github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/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 provides testing utilities related to
     5  // the logsender package.
     6  package logsendertest
     7  
     8  import (
     9  	"reflect"
    10  
    11  	gc "gopkg.in/check.v1"
    12  
    13  	"github.com/juju/juju/testing"
    14  	"github.com/juju/juju/worker/logsender"
    15  )
    16  
    17  // ExpectLogStats waits for the buffered log writer's
    18  // statistics to match the expected value. This is
    19  // provided because statistics are updated after
    20  // log messages are handed off to the sink, and so
    21  // tests must cater for the gap or races will occur.
    22  func ExpectLogStats(c *gc.C, writer *logsender.BufferedLogWriter, expect logsender.LogStats) {
    23  	var stats logsender.LogStats
    24  	for a := testing.LongAttempt.Start(); a.Next(); {
    25  		stats = writer.Stats()
    26  		if reflect.DeepEqual(stats, expect) {
    27  			return
    28  		}
    29  	}
    30  	c.Errorf("timed out waiting for statistics: got %+v, expected %+v", stats, expect)
    31  }