X7ROOT File Manager
Current Path:
/opt/golang/1.22.0/src/time
opt
/
golang
/
1.22.0
/
src
/
time
/
📁
..
📄
embed.go
(304 B)
📄
example_test.go
(22.43 KB)
📄
export_android_test.go
(438 B)
📄
export_test.go
(3.96 KB)
📄
export_windows_test.go
(514 B)
📄
format.go
(48.45 KB)
📄
format_rfc3339.go
(5.68 KB)
📄
format_test.go
(35.92 KB)
📄
genzabbrs.go
(2.95 KB)
📄
internal_test.go
(2.21 KB)
📄
mono_test.go
(8.29 KB)
📄
sleep.go
(5.66 KB)
📄
sleep_test.go
(18.5 KB)
📄
sys_plan9.go
(1016 B)
📄
sys_unix.go
(1.38 KB)
📄
sys_windows.go
(1.1 KB)
📁
testdata
📄
tick.go
(2.28 KB)
📄
tick_test.go
(4.01 KB)
📄
time.go
(49.63 KB)
📄
time_test.go
(56.04 KB)
📁
tzdata
📄
tzdata_test.go
(2.46 KB)
📄
zoneinfo.go
(18.15 KB)
📄
zoneinfo_abbrs_windows.go
(10.48 KB)
📄
zoneinfo_android.go
(2.19 KB)
📄
zoneinfo_android_test.go
(386 B)
📄
zoneinfo_goroot.go
(348 B)
📄
zoneinfo_ios.go
(1.05 KB)
📄
zoneinfo_js.go
(1.03 KB)
📄
zoneinfo_plan9.go
(2.69 KB)
📄
zoneinfo_read.go
(14.31 KB)
📄
zoneinfo_test.go
(9.91 KB)
📄
zoneinfo_unix.go
(1.69 KB)
📄
zoneinfo_unix_test.go
(2.31 KB)
📄
zoneinfo_wasip1.go
(307 B)
📄
zoneinfo_windows.go
(6.57 KB)
📄
zoneinfo_windows_test.go
(1.84 KB)
Editing: tick_test.go
// Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package time_test import ( "fmt" "runtime" "testing" . "time" ) func TestTicker(t *testing.T) { // We want to test that a ticker takes as much time as expected. // Since we don't want the test to run for too long, we don't // want to use lengthy times. This makes the test inherently flaky. // Start with a short time, but try again with a long one if the // first test fails. baseCount := 10 baseDelta := 20 * Millisecond // On Darwin ARM64 the tick frequency seems limited. Issue 35692. if (runtime.GOOS == "darwin" || runtime.GOOS == "ios") && runtime.GOARCH == "arm64" { // The following test will run ticker count/2 times then reset // the ticker to double the duration for the rest of count/2. // Since tick frequency is limited on Darwin ARM64, use even // number to give the ticks more time to let the test pass. // See CL 220638. baseCount = 6 baseDelta = 100 * Millisecond } var errs []string logErrs := func() { for _, e := range errs { t.Log(e) } } for _, test := range []struct { count int delta Duration }{{ count: baseCount, delta: baseDelta, }, { count: 8, delta: 1 * Second, }} { count, delta := test.count, test.delta ticker := NewTicker(delta) t0 := Now() for i := 0; i < count/2; i++ { <-ticker.C } ticker.Reset(delta * 2) for i := count / 2; i < count; i++ { <-ticker.C } ticker.Stop() t1 := Now() dt := t1.Sub(t0) target := 3 * delta * Duration(count/2) slop := target * 3 / 10 if dt < target-slop || dt > target+slop { errs = append(errs, fmt.Sprintf("%d %s ticks then %d %s ticks took %s, expected [%s,%s]", count/2, delta, count/2, delta*2, dt, target-slop, target+slop)) if dt > target+slop { // System may be overloaded; sleep a bit // in the hopes it will recover. Sleep(Second / 2) } continue } // Now test that the ticker stopped. Sleep(2 * delta) select { case <-ticker.C: errs = append(errs, "Ticker did not shut down") continue default: // ok } // Test passed, so all done. if len(errs) > 0 { t.Logf("saw %d errors, ignoring to avoid flakiness", len(errs)) logErrs() } return } t.Errorf("saw %d errors", len(errs)) logErrs() } // Issue 21874 func TestTickerStopWithDirectInitialization(t *testing.T) { c := make(chan Time) tk := &Ticker{C: c} tk.Stop() } // Test that a bug tearing down a ticker has been fixed. This routine should not deadlock. func TestTeardown(t *testing.T) { Delta := 100 * Millisecond if testing.Short() { Delta = 20 * Millisecond } for i := 0; i < 3; i++ { ticker := NewTicker(Delta) <-ticker.C ticker.Stop() } } // Test the Tick convenience wrapper. func TestTick(t *testing.T) { // Test that giving a negative duration returns nil. if got := Tick(-1); got != nil { t.Errorf("Tick(-1) = %v; want nil", got) } } // Test that NewTicker panics when given a duration less than zero. func TestNewTickerLtZeroDuration(t *testing.T) { defer func() { if err := recover(); err == nil { t.Errorf("NewTicker(-1) should have panicked") } }() NewTicker(-1) } // Test that Ticker.Reset panics when given a duration less than zero. func TestTickerResetLtZeroDuration(t *testing.T) { defer func() { if err := recover(); err == nil { t.Errorf("Ticker.Reset(0) should have panicked") } }() tk := NewTicker(Second) tk.Reset(0) } func BenchmarkTicker(b *testing.B) { benchmark(b, func(n int) { ticker := NewTicker(Nanosecond) for i := 0; i < n; i++ { <-ticker.C } ticker.Stop() }) } func BenchmarkTickerReset(b *testing.B) { benchmark(b, func(n int) { ticker := NewTicker(Nanosecond) for i := 0; i < n; i++ { ticker.Reset(Nanosecond * 2) } ticker.Stop() }) } func BenchmarkTickerResetNaive(b *testing.B) { benchmark(b, func(n int) { ticker := NewTicker(Nanosecond) for i := 0; i < n; i++ { ticker.Stop() ticker = NewTicker(Nanosecond * 2) } ticker.Stop() }) }
Upload File
Create Folder