Merge lp:~rogpeppe/gocheck/monotonic-time-stamps into lp:gocheck

Proposed by Roger Peppe
Status: Merged
Merged at revision: 87
Proposed branch: lp:~rogpeppe/gocheck/monotonic-time-stamps
Merge into: lp:gocheck
Diff against target: 207 lines (+38/-40)
8 files modified
benchmark_test.go (+6/-6)
bootstrap_test.go (+1/-1)
foundation_test.go (+2/-7)
gocheck.go (+10/-9)
gocheck_test.go (+7/-7)
helpers.go (+6/-3)
run.go (+5/-5)
run_test.go (+1/-2)
To merge this branch: bzr merge lp:~rogpeppe/gocheck/monotonic-time-stamps
Reviewer Review Type Date Requested Status
Gustavo Niemeyer Pending
Review via email: mp+98841@code.launchpad.net

Description of the change

Use readable time stamps on log messages.

On long running tests, the time might wrap:

[LOG] 72.15087 JUJU state: opening state; zookeeper addresses: ["ec2-23-20-157-185.compute-1.amazonaws.com:2181"]
[LOG] 78.46405 JUJU state: waiting for state to be initialized
destroy env
[LOG] 13.73135 JUJU environs/ec2: destroying environment "sample-6326978ae3647455"

This CL makes the time stamp format as a duration since
the start of the test in the format agreed before:

[LOG] 0:00.568 DEBUG juju.environs.tools reading v1.* tools
[LOG] 0:00.569 INFO juju environs/testing: uploading FAKE tools 1.17.3-trusty-amd64
[LOG] 0:00.570 INFO juju environs/testing: uploading FAKE tools 1.17.3-precise-amd64
[LOG] 0:00.571 DEBUG juju.environs.tools no architecture specified when finding tools, looking for any

https://codereview.appspot.com/5874049/

To post a comment you must log in.
Revision history for this message
Roger Peppe (rogpeppe) wrote :
Download full text (7.5 KiB)

Reviewers: mp+98841_code.launchpad.net,

Message:
Please take a look.

Description:
use readable time stamps on log messages.

On long running tests, I was seeing log output like this:

[LOG] 72.15087 JUJU state: opening state; zookeeper addresses:
["ec2-23-20-157-185.compute-1.amazonaws.com:2181"]
[LOG] 78.46405 JUJU state: waiting for state to be initialized
destroy env
[LOG] 13.73135 JUJU environs/ec2: destroying environment
"sample-6326978ae3647455"

This CL makes the time stamp format as a duration
since the start of the test. For instance:

[LOG] 139us JUJU environs/ec2: bootstrapping environment
"sample-92839ff36fe291dd"
[LOG] 7.273315s JUJU environs/ec2: started instance "i-69f7a10d"
[LOG] 14.822193s JUJU environs/ec2: bootstrapping environment
"sample-92839ff36fe291dd"

For consideration: we could also round to milliseconds (nanosecond time
stamps are rarely useful in logs).

https://code.launchpad.net/~rogpeppe/gocheck/monotonic-time-stamps/+merge/98841

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/5874049/

Affected files:
   A [revision details]
   M bootstrap_test.go
   M checkers.go
   M foundation_test.go
   M gocheck.go
   M gocheck_test.go
   M helpers.go
   M helpers_test.go
   M run.go
   M run_test.go

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: <email address hidden>
+New revision: <email address hidden>

Index: bootstrap_test.go
=== modified file 'bootstrap_test.go'
--- bootstrap_test.go 2011-11-08 15:09:50 +0000
+++ bootstrap_test.go 2012-03-22 13:59:07 +0000
@@ -13,9 +13,9 @@
  package gocheck_test

  import (
+ "fmt"
   "launchpad.net/gocheck"
   "strings"
- "fmt"
  )

  type BootstrapS struct{}

Index: checkers.go
=== modified file 'checkers.go'
--- checkers.go 2012-02-25 19:01:16 +0000
+++ checkers.go 2012-03-22 13:59:07 +0000
@@ -1,9 +1,9 @@
  package gocheck

  import (
+ "fmt"
   "reflect"
   "regexp"
- "fmt"
  )

  // -----------------------------------------------------------------------
@@ -238,7 +238,6 @@
   return value.Len() == n, ""
  }

-
  // -----------------------------------------------------------------------
  // ErrorMatches checker.

Index: foundation_test.go
=== modified file 'foundation_test.go'
--- foundation_test.go 2012-02-25 16:58:37 +0000
+++ foundation_test.go 2012-03-22 13:59:07 +0000
@@ -7,12 +7,12 @@
  package gocheck_test

  import (
+ "fmt"
   "launchpad.net/gocheck"
- "strings"
- "regexp"
- "fmt"
   "log"
   "os"
+ "regexp"
+ "strings"
  )

  // -----------------------------------------------------------------------
@@ -301,14 +301,9 @@
   logger = log.New(os.Stderr, "", 0)
   logger = c
   logger.Output(0, "Hello there")
- expected := "\\[LOG\\] [.0-9]+ Hello there\n"
+ expected := `\[LOG\] [0-9]+(\.[0-9]+)?[mun]?s +Hello there\n`
   output := c.GetTestLog()
- matched, err := regexp.MatchString(expected, output)
- if err != nil {
- c.Error("Bad expression: ", expected)
- } else if !matched {
- c.Error("Out...

Read more...

Revision history for this message
Roger Peppe (rogpeppe) wrote :
Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

This has already been fixed in the last release, following up a
conversation we had online and a format we both agreed with.

https://codereview.appspot.com/5874049/

Revision history for this message
Roger Peppe (rogpeppe) wrote :
Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'benchmark_test.go'
--- benchmark_test.go 2013-03-02 02:47:45 +0000
+++ benchmark_test.go 2014-02-18 17:08:13 +0000
@@ -40,10 +40,10 @@
40 helper := FixtureHelper{sleep: 100000}40 helper := FixtureHelper{sleep: 100000}
41 output := String{}41 output := String{}
42 runConf := RunConf{42 runConf := RunConf{
43 Output: &output,43 Output: &output,
44 Benchmark: true,44 Benchmark: true,
45 BenchmarkTime: 10000000,45 BenchmarkTime: 10000000,
46 Filter: "Benchmark1",46 Filter: "Benchmark1",
47 }47 }
48 Run(&helper, &runConf)48 Run(&helper, &runConf)
49 c.Check(helper.calls[0], Equals, "SetUpSuite")49 c.Check(helper.calls[0], Equals, "SetUpSuite")
@@ -63,10 +63,10 @@
63 helper := FixtureHelper{sleep: 100000}63 helper := FixtureHelper{sleep: 100000}
64 output := String{}64 output := String{}
65 runConf := RunConf{65 runConf := RunConf{
66 Output: &output,66 Output: &output,
67 Benchmark: true,67 Benchmark: true,
68 BenchmarkTime: 10000000,68 BenchmarkTime: 10000000,
69 Filter: "Benchmark2",69 Filter: "Benchmark2",
70 }70 }
71 Run(&helper, &runConf)71 Run(&helper, &runConf)
7272
7373
=== modified file 'bootstrap_test.go'
--- bootstrap_test.go 2012-02-28 15:14:09 +0000
+++ bootstrap_test.go 2014-02-18 17:08:13 +0000
@@ -1,7 +1,7 @@
1// These initial tests are for bootstrapping. They verify that we can1// These initial tests are for bootstrapping. They verify that we can
2// basically use the testing infrastructure itself to check if the test2// basically use the testing infrastructure itself to check if the test
3// system is working.3// system is working.
4// 4//
5// These tests use will break down the test runner badly in case of5// These tests use will break down the test runner badly in case of
6// errors because if they simply fail, we can't be sure the developer6// errors because if they simply fail, we can't be sure the developer
7// will ever see anything (because failing means the failing system7// will ever see anything (because failing means the failing system
88
=== modified file 'foundation_test.go'
--- foundation_test.go 2013-03-01 22:15:07 +0000
+++ foundation_test.go 2014-02-18 17:08:13 +0000
@@ -301,14 +301,9 @@
301 logger = log.New(os.Stderr, "", 0)301 logger = log.New(os.Stderr, "", 0)
302 logger = c302 logger = c
303 logger.Output(0, "Hello there")303 logger.Output(0, "Hello there")
304 expected := "\\[LOG\\] [.0-9]+ Hello there\n"304 expected := `\[LOG\] [0-9]+:[0-9][0-9]\.[0-9][0-9][0-9] +Hello there\n`
305 output := c.GetTestLog()305 output := c.GetTestLog()
306 matched, err := regexp.MatchString(expected, output)306 c.Assert(output, gocheck.Matches, expected)
307 if err != nil {
308 c.Error("Bad expression: ", expected)
309 } else if !matched {
310 c.Error("Output() didn't log properly:\n", output)
311 }
312}307}
313308
314// -----------------------------------------------------------------------309// -----------------------------------------------------------------------
315310
=== modified file 'gocheck.go'
--- gocheck.go 2013-03-02 02:47:45 +0000
+++ gocheck.go 2014-02-18 17:08:13 +0000
@@ -62,7 +62,7 @@
62}62}
6363
64func (method *methodType) String() string {64func (method *methodType) String() string {
65 return method.suiteName()+"."+method.Info.Name65 return method.suiteName() + "." + method.Info.Name
66}66}
6767
68func (method *methodType) matches(re *regexp.Regexp) bool {68func (method *methodType) matches(re *regexp.Regexp) bool {
@@ -81,6 +81,7 @@
81 reason string81 reason string
82 mustFail bool82 mustFail bool
83 tempDir *tempDir83 tempDir *tempDir
84 startTime time.Time
84 timer85 timer
85}86}
8687
@@ -613,13 +614,14 @@
613 logb = new(logger)614 logb = new(logger)
614 }615 }
615 c := &C{616 c := &C{
616 method: method,617 method: method,
617 kind: kind,618 kind: kind,
618 logb: logb,619 logb: logb,
619 logw: logw,620 logw: logw,
620 tempDir: runner.tempDir,621 tempDir: runner.tempDir,
621 done: make(chan *C, 1),622 done: make(chan *C, 1),
622 timer: timer{benchTime: runner.benchTime},623 timer: timer{benchTime: runner.benchTime},
624 startTime: time.Now(),
623 }625 }
624 runner.tracker.expectCall(c)626 runner.tracker.expectCall(c)
625 go (func() {627 go (func() {
@@ -913,4 +915,3 @@
913 return fmt.Sprintf("%s%s: %s: %s%s", prefix, label, niceFuncPath(pc),915 return fmt.Sprintf("%s%s: %s: %s%s", prefix, label, niceFuncPath(pc),
914 niceFuncName(pc), suffix)916 niceFuncName(pc), suffix)
915}917}
916
917918
=== modified file 'gocheck_test.go'
--- gocheck_test.go 2013-03-02 02:47:45 +0000
+++ gocheck_test.go 2014-02-18 17:08:13 +0000
@@ -94,13 +94,13 @@
94// Helper suite for testing ordering and behavior of fixture.94// Helper suite for testing ordering and behavior of fixture.
9595
96type FixtureHelper struct {96type FixtureHelper struct {
97 calls []string97 calls []string
98 panicOn string98 panicOn string
99 skip bool99 skip bool
100 skipOnN int100 skipOnN int
101 sleepOn string101 sleepOn string
102 sleep time.Duration102 sleep time.Duration
103 bytes int64103 bytes int64
104}104}
105105
106func (s *FixtureHelper) trace(name string, c *gocheck.C) {106func (s *FixtureHelper) trace(name string, c *gocheck.C) {
107107
=== modified file 'helpers.go'
--- helpers.go 2012-02-25 16:58:37 +0000
+++ helpers.go 2014-02-18 17:08:13 +0000
@@ -92,9 +92,12 @@
92// Output enables *C to be used as a logger in functions that require only92// Output enables *C to be used as a logger in functions that require only
93// the minimum interface of *log.Logger.93// the minimum interface of *log.Logger.
94func (c *C) Output(calldepth int, s string) error {94func (c *C) Output(calldepth int, s string) error {
95 ns := time.Now().Sub(time.Time{}).Nanoseconds()95 d := time.Now().Sub(c.startTime)
96 t := float64(ns%100e9) / 1e996 msec := d / time.Millisecond
97 c.Logf("[LOG] %.05f %s", t, s)97 sec := d / time.Second
98 min := d / time.Minute
99
100 c.Logf("[LOG] %d:%02d.%03d %s", min, sec%60, msec%1000, s)
98 return nil101 return nil
99}102}
100103
101104
=== modified file 'run.go'
--- run.go 2013-03-01 22:15:07 +0000
+++ run.go 2014-02-18 17:08:13 +0000
@@ -30,7 +30,7 @@
30 verboseFlag = flag.Bool("gocheck.v", false, "Verbose mode")30 verboseFlag = flag.Bool("gocheck.v", false, "Verbose mode")
31 streamFlag = flag.Bool("gocheck.vv", false, "Super verbose mode (disables output caching)")31 streamFlag = flag.Bool("gocheck.vv", false, "Super verbose mode (disables output caching)")
32 benchFlag = flag.Bool("gocheck.b", false, "Run benchmarks")32 benchFlag = flag.Bool("gocheck.b", false, "Run benchmarks")
33 benchTime = flag.Duration("gocheck.btime", 1 * time.Second, "approximate run time for each benchmark")33 benchTime = flag.Duration("gocheck.btime", 1*time.Second, "approximate run time for each benchmark")
34 listFlag = flag.Bool("gocheck.list", false, "List the names of all tests that will be run")34 listFlag = flag.Bool("gocheck.list", false, "List the names of all tests that will be run")
35)35)
3636
@@ -39,10 +39,10 @@
39// module.39// module.
40func TestingT(testingT *testing.T) {40func TestingT(testingT *testing.T) {
41 conf := &RunConf{41 conf := &RunConf{
42 Filter: *filterFlag,42 Filter: *filterFlag,
43 Verbose: *verboseFlag,43 Verbose: *verboseFlag,
44 Stream: *streamFlag,44 Stream: *streamFlag,
45 Benchmark: *benchFlag,45 Benchmark: *benchFlag,
46 BenchmarkTime: *benchTime,46 BenchmarkTime: *benchTime,
47 }47 }
48 if *listFlag {48 if *listFlag {
4949
=== modified file 'run_test.go'
--- run_test.go 2013-03-02 02:47:45 +0000
+++ run_test.go 2014-02-18 17:08:13 +0000
@@ -2,7 +2,6 @@
22
3package gocheck_test3package gocheck_test
44
5
6import (5import (
7 "errors"6 "errors"
8 . "launchpad.net/gocheck"7 . "launchpad.net/gocheck"
@@ -299,7 +298,7 @@
299}298}
300299
301// -----------------------------------------------------------------------300// -----------------------------------------------------------------------
302// Verify that verbose mode prints tests which pass as well. 301// Verify that verbose mode prints tests which pass as well.
303302
304func (s *RunS) TestVerboseMode(c *C) {303func (s *RunS) TestVerboseMode(c *C) {
305 helper := FixtureHelper{}304 helper := FixtureHelper{}

Subscribers

People subscribed via source and target branches