Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log: TestUTCFlag is flaky #11272

Closed
RLH opened this issue Jun 18, 2015 · 1 comment
Closed

log: TestUTCFlag is flaky #11272

RLH opened this issue Jun 18, 2015 · 1 comment
Milestone

Comments

@RLH
Copy link
Contributor

RLH commented Jun 18, 2015

rlh@rlh0:~/work/go/src/log$ go version
go version devel +d6ce3b2 Thu Jun 18 11:35:11 2015 -0400 linux/amd64
rlh@rlh0:~/work/go/src/log$ stress ./log.test -test.v

/tmp/go-stress150315426
=== RUN   TestAll
--- PASS: TestAll (0.00s)
=== RUN   TestOutput
--- PASS: TestOutput (0.00s)
=== RUN   TestFlagAndPrefixSetting
--- PASS: TestFlagAndPrefixSetting (0.00s)
=== RUN   TestUTCFlag
--- FAIL: TestUTCFlag (0.00s)
    log_test.go:145: got "Test:2015/06/18 16:10:29 hello\n"; want "Test:2015/06/18 16:10:%!d(MISSING) hello\n"
=== RUN   TestEmptyPrintCreatesLine
--- PASS: TestEmptyPrintCreatesLine (0.00s)
=== RUN   ExampleLogger
--- PASS: ExampleLogger (0.00s)
FAIL


ERROR: exit status 1

5677 runs so far

--- The second fmt.Sprintf looks like it is missing a now.Second()

func TestUTCFlag(t *testing.T) {
    var b bytes.Buffer
    l := New(&b, "Test:", LstdFlags)
    l.SetFlags(Ldate | Ltime | LUTC)
    // Verify a log message looks right in the right time zone. Quantize to the second only.
    now := time.Now().UTC()
    l.Print("hello")
    want := fmt.Sprintf("Test:%d/%.2d/%.2d %.2d:%.2d:%.2d hello\n",
        now.Year(), now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second())
    got := b.String()
    if got == want {
        return
    }
    // It's possible we crossed a second boundary between getting now and logging,
    // so add a second and try again. This should very nearly always work.
    now.Add(time.Second)
    want = fmt.Sprintf("Test:%d/%.2d/%.2d %.2d:%.2d:%.2d hello\n",
        now.Year(), now.Month(), now.Day(), now.Hour(), now.Minute())
    if got == want {
        return
    }
    t.Errorf("got %q; want %q", got, want)
}
@josharian josharian added this to the Go1.5 milestone Jun 18, 2015
@josharian josharian self-assigned this Jun 18, 2015
@josharian josharian changed the title TestUTCFlag: Sprintf log: TestUTCFlag is flaky Jun 18, 2015
@gopherbot
Copy link

CL https://golang.org/cl/11234 mentions this issue.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants