diff --git a/cert/cert.go b/cert/cert.go index 87af6d9f0..277f531f0 100644 --- a/cert/cert.go +++ b/cert/cert.go @@ -1,6 +1,6 @@ // Copyright 2012, 2013 Canonical Ltd. // Copyright 2016 Cloudbase solutions -// Licensed under the AGPLv3, see LICENCE file for details. +// Licensed under the LGPLv3, see LICENCE file for details. package cert diff --git a/cert/cert_test.go b/cert/cert_test.go index 218af8cc1..4881737c8 100644 --- a/cert/cert_test.go +++ b/cert/cert_test.go @@ -1,6 +1,6 @@ // Copyright 2012, 2013 Canonical Ltd. // Copyright 2016 Cloudbase solutions -// Licensed under the AGPLv3, see LICENCE file for details. +// Licensed under the LGPLv3, see LICENCE file for details. package cert_test diff --git a/cert/exports_test.go b/cert/exports_test.go index d273b54ed..add340b01 100644 --- a/cert/exports_test.go +++ b/cert/exports_test.go @@ -1,6 +1,6 @@ // Copyright 2016 Canonical ltd. // Copyright 2016 Cloudbase solutions -// Licensed under the lgplv3, see licence file for details. +// Licensed under the LGPLv3, see LICENCE file for details. package cert diff --git a/clock/clock.go b/clock/clock.go deleted file mode 100644 index 59a511d05..000000000 --- a/clock/clock.go +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2015 Canonical Ltd. -// Licensed under the LGPLv3, see LICENCE file for details. - -package clock - -import "time" - -// Clock provides an interface for dealing with clocks. -type Clock interface { - // Now returns the current clock time. - Now() time.Time - - // After waits for the duration to elapse and then sends the - // current time on the returned channel. - After(time.Duration) <-chan time.Time - - // AfterFunc waits for the duration to elapse and then calls f in its own goroutine. - // It returns a Timer that can be used to cancel the call using its Stop method. - AfterFunc(d time.Duration, f func()) Timer - - // NewTimer creates a new Timer that will send the current time - // on its channel after at least duration d. - NewTimer(d time.Duration) Timer -} - -// Alarm returns a channel that will have the time sent on it at some point -// after the supplied time occurs. -// -// This is short for c.After(t.Sub(c.Now())). -func Alarm(c Clock, t time.Time) <-chan time.Time { - return c.After(t.Sub(c.Now())) -} - -// The Timer type represents a single event. -// A Timer must be created with AfterFunc. -// This interface follows time.Timer's methods but provides easier mocking. -type Timer interface { - // When the Timer expires, the current time will be sent on the - // channel returned from Chan, unless the Timer was created by - // AfterFunc. - Chan() <-chan time.Time - - // Reset changes the timer to expire after duration d. - // It returns true if the timer had been active, false if - // the timer had expired or been stopped. - Reset(time.Duration) bool - - // Stop prevents the Timer from firing. It returns true if - // the call stops the timer, false if the timer has already expired or been stopped. - // Stop does not close the channel, to prevent a read - // from the channel succeeding incorrectly. - Stop() bool -} diff --git a/clock/monotonic/monotonic.go b/clock/monotonic/monotonic.go deleted file mode 100644 index 6941ed455..000000000 --- a/clock/monotonic/monotonic.go +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2017 Canonical Ltd. -// Licensed under the LGPLv3, see LICENCE file for details. - -package monotonic - -import ( - "time" - _ "unsafe" -) - -//go:noescape -//go:linkname nanotime runtime.nanotime -func nanotime() int64 - -// Now returns the current time in nanoseconds from a monotonic clock. -// -// The result is guaranteed to not jump due to NTP or other changes to -// system time, which may jump forward or backwards. Instead, in response to -// such changes, the clock frequency is adjusted slowly. -func Now() time.Duration { - return time.Duration(nanotime()) -} diff --git a/clock/monotonic/monotonic.s b/clock/monotonic/monotonic.s deleted file mode 100644 index 6f9f4945f..000000000 --- a/clock/monotonic/monotonic.s +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright 2017 Canonical Ltd. -// Licensed under the LGPLv3, see LICENCE file for details. - -// Deliberately empty - see https://github.com/golang/go/issues/15006 diff --git a/clock/monotonic/monotonic_test.go b/clock/monotonic/monotonic_test.go deleted file mode 100644 index 7198c02a9..000000000 --- a/clock/monotonic/monotonic_test.go +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2017 Canonical Ltd. -// Licensed under the LGPLv3, see LICENCE file for details. - -package monotonic_test - -import ( - "testing" - "time" - - gc "gopkg.in/check.v1" - - "github.com/juju/utils/clock/monotonic" -) - -func TestPackage(t *testing.T) { - gc.TestingT(t) -} - -type MonotonicSuite struct { -} - -var _ = gc.Suite(&MonotonicSuite{}) - -func (s *MonotonicSuite) TestNow(c *gc.C) { - var prev time.Duration - for i := 0; i < 1000; i++ { - val := monotonic.Now() - if val < prev { - c.Fatal("now is less than previous value") - } - prev = val - } -} diff --git a/clock/wall.go b/clock/wall.go deleted file mode 100644 index 9bfc35185..000000000 --- a/clock/wall.go +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2015 Canonical Ltd. -// Licensed under the LGPLv3, see LICENCE file for details. - -package clock - -import ( - "time" -) - -// WallClock exposes wall-clock time via the Clock interface. -var WallClock wallClock - -// ensure that WallClock does actually implement the Clock interface. -var _ Clock = WallClock - -// WallClock exposes wall-clock time as returned by time.Now. -type wallClock struct{} - -// Now is part of the Clock interface. -func (wallClock) Now() time.Time { - return time.Now() -} - -// After implements Clock.After. -func (wallClock) After(d time.Duration) <-chan time.Time { - return time.After(d) -} - -// AfterFunc implements Clock.AfterFunc. -func (wallClock) AfterFunc(d time.Duration, f func()) Timer { - return wallTimer{time.AfterFunc(d, f)} -} - -// NewTimer implements Clock.NewTimer. -func (wallClock) NewTimer(d time.Duration) Timer { - return wallTimer{time.NewTimer(d)} -} - -// wallTimer implements the Timer interface. -type wallTimer struct { - *time.Timer -} - -// Chan implements Timer.Chan. -func (t wallTimer) Chan() <-chan time.Time { - return t.C -} diff --git a/context.go b/context.go index d90790676..8cf3f1ccf 100644 --- a/context.go +++ b/context.go @@ -1,3 +1,6 @@ +// Copyright 2018 Canonical Ltd. +// Licensed under the LGPLv3, see LICENCE file for details. + package utils import ( @@ -7,7 +10,7 @@ import ( "golang.org/x/net/context" - "github.com/juju/utils/clock" + "github.com/juju/clock" ) // timerCtx is an implementation of context.Context that diff --git a/context_test.go b/context_test.go index 38b9ca257..a33c8716a 100644 --- a/context_test.go +++ b/context_test.go @@ -1,3 +1,6 @@ +// Copyright 2018 Canonical Ltd. +// Licensed under the LGPLv3, see LICENCE file for details. + package utils_test import ( @@ -6,7 +9,7 @@ import ( "golang.org/x/net/context" - "github.com/juju/testing" + "github.com/juju/clock/testclock" jc "github.com/juju/testing/checkers" gc "gopkg.in/check.v1" @@ -21,7 +24,7 @@ var _ = gc.Suite(&contextSuite{}) // in the Go standard library. func (*contextSuite) TestDeadline(c *gc.C) { - clk := testing.NewClock(time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC)) + clk := testclock.NewClock(time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC)) ctx, cancel := utils.ContextWithDeadline(context.Background(), clk, clk.Now().Add(50*time.Millisecond)) defer cancel() c.Assert(fmt.Sprint(ctx), gc.Equals, `context.Background.WithDeadline(2000-01-01 00:00:00.05 +0000 UTC [50ms])`) @@ -47,7 +50,7 @@ func (*contextSuite) TestDeadline(c *gc.C) { } func (*contextSuite) TestTimeout(c *gc.C) { - clk := testing.NewClock(time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC)) + clk := testclock.NewClock(time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC)) ctx, _ := utils.ContextWithTimeout(context.Background(), clk, 50*time.Millisecond) c.Assert(fmt.Sprint(ctx), gc.Equals, `context.Background.WithDeadline(2000-01-01 00:00:00.05 +0000 UTC [50ms])`) testContextDeadline(c, ctx, "WithTimeout", clk, 1, 50*time.Millisecond) @@ -63,7 +66,7 @@ func (*contextSuite) TestTimeout(c *gc.C) { } func (*contextSuite) TestCanceledTimeout(c *gc.C) { - clk := testing.NewClock(time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC)) + clk := testclock.NewClock(time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC)) ctx, _ := utils.ContextWithTimeout(context.Background(), clk, time.Second) o := otherContext{ctx} ctx, cancel := utils.ContextWithTimeout(o, clk, 2*time.Second) @@ -77,7 +80,7 @@ func (*contextSuite) TestCanceledTimeout(c *gc.C) { c.Assert(ctx.Err(), gc.Equals, context.Canceled) } -func testContextDeadline(c *gc.C, ctx context.Context, name string, clk *testing.Clock, waiters int, failAfter time.Duration) { +func testContextDeadline(c *gc.C, ctx context.Context, name string, clk *testclock.Clock, waiters int, failAfter time.Duration) { err := clk.WaitAdvance(failAfter, 0, waiters) c.Assert(err, jc.ErrorIsNil) select { diff --git a/dependencies.tsv b/dependencies.tsv index 62dfda569..26fa91e8c 100644 --- a/dependencies.tsv +++ b/dependencies.tsv @@ -1,12 +1,13 @@ github.com/juju/ansiterm git b99631de12cf04a906c1d4e4ec54fb86eae5863d 2016-09-07T23:45:32Z -github.com/juju/cmd git ad2437ef0ef282ae26e482eb1e44c02532bae1ba 2017-06-22T12:53:07Z +github.com/juju/clock git d293bb356ca441f16b59562295cca74478966757 2018-05-24T02:22:03Z +github.com/juju/cmd git e74f39857ca013cf63947ba2843806f7afdd380d 2017-11-07T07:04:56Z github.com/juju/errors git 1b5e39b83d1835fa480e0c2ddefb040ee82d58b3 2015-09-16T12:56:42Z -github.com/juju/gnuflag git 4e76c56581859c14d9d87e1ddbe29e1c0f10195f 2016-08-09T16:52:14Z +github.com/juju/gnuflag git 2ce1bb71843d6d179b3f1c1c9cb4a72cd067fc65 2017-11-13T08:59:48Z github.com/juju/httpprof git 14bf14c307672fd2456bdbf35d19cf0ccd3cf565 2014-12-17T16:00:36Z github.com/juju/loggo git 8232ab8918d91c72af1a9fb94d3edbe31d88b790 2017-06-05T01:46:07Z -github.com/juju/mutex git 59c26ee163447c5c57f63ff71610d433862013de 2016-06-17T01:09:07Z -github.com/juju/retry git 62c62032529169c7ec02fa48f93349604c345e1f 2015-10-29T02:48:21Z -github.com/juju/testing git 2fe0e88cf2321d801acedd2b4f0d7f63735fb732 2017-06-08T05:44:51Z +github.com/juju/mutex git 1fe2a4bf0a3a2c10881501233ff7c6aed7790082 2017-11-10T02:00:13Z +github.com/juju/retry git 1998d01ba1c3eeb4a4728c4a50660025b2fe7c8f 2016-09-28T20:18:58Z +github.com/juju/testing git b0b89ba330f22548fba865dd0e1d85a44e9cd7dd 2018-08-20T04:02:00Z github.com/juju/version git 1f41e27e54f21acccf9b2dddae063a782a8a7ceb 2016-10-31T05:19:06Z github.com/julienschmidt/httprouter git 77a895ad01ebc98a4dc95d8355bc825ce80a56f6 2015-10-13T22:55:20Z github.com/lunixbochs/vtclean git 4fbf7632a2c6d3fbdb9931439bdbbeded02cbe36 2016-01-25T03:51:06Z @@ -17,14 +18,14 @@ github.com/masterzen/xmlpath git 13f4951698adc0fa9c1dda3e275d489a24201161 2014-0 github.com/mattn/go-colorable git ed8eb9e318d7a84ce5915b495b7d35e0cfe7b5a8 2016-07-31T23:54:17Z github.com/mattn/go-isatty git 66b8e73f3f5cda9f96b69efd03dd3d7fc4a5cdb8 2016-08-06T12:27:52Z github.com/nu7hatch/gouuid git 179d4d0c4d8d407a32af483c2354df1d2c91e6c3 2013-12-21T20:05:32Z -golang.org/x/crypto git 96846453c37f0876340a66a47f3f75b1f3a6cd2d 2017-04-21T04:31:20Z -golang.org/x/net git a04bdaca5b32abe1c069418fb7088ae607de5bd0 2017-10-04T03:46:48Z -golang.org/x/sys git 7a6e5648d140666db5d920909e082ca00a87ba2c 2017-02-01T05:12:45Z -golang.org/x/text git 88f656faf3f37f690df1a32515b479415e1a6769 2017-11-02T19:24:21Z +golang.org/x/crypto git 650f4a345ab4e5b245a3034b110ebc7299e68186 2018-02-14T00:00:28Z +golang.org/x/net git 61147c48b25b599e5b561d2e9c4f3e1ef489ca41 2018-04-06T21:48:16Z +golang.org/x/sys git 37707fdb30a5b38865cfb95e5aab41707daec7fd 2018-02-02T13:58:01Z +golang.org/x/text git 2910a502d2bf9e43193af9d68ca516529614eed3 2016-07-26T16:48:57Z gopkg.in/check.v1 git 4f90aeace3a26ad7021961c297b22c42160c7b25 2016-01-05T16:49:36Z gopkg.in/errgo.v1 git 442357a80af5c6bf9b6d51ae791a39c3421004f3 2016-12-22T12:58:16Z -gopkg.in/httprequest.v1 git 35158f716c228fdf58b5a5b80cf331302d10160a 2017-11-03T09:19:05Z -gopkg.in/juju/names.v2 git 0f8ae7499c60de56e4cb4c5eabe2d504615a18ca 2017-05-15T22:48:47Z +gopkg.in/httprequest.v1 git 1a21782420ea13c3c6fb1d03578f446b3248edb1 2018-03-08T16:26:44Z +gopkg.in/juju/names.v2 git c43e8bdf2f4915a7019a2f8ad561af1498731a21 2018-05-16T01:04:14Z gopkg.in/mgo.v2 git f2b6f6c918c452ad107eec89615f074e3bd80e33 2016-08-18T01:52:18Z gopkg.in/tomb.v1 git dd632973f1e7218eb1089048e0798ec9ae7dceb8 2014-10-24T13:56:13Z -gopkg.in/yaml.v2 git a3f3340b5840cee44f372bddb5880fcbc419b46a 2017-02-08T14:18:51Z +gopkg.in/yaml.v2 git 1be3d31502d6eabc0dd7ce5b0daab022e14a5538 2017-07-12T05:45:46Z diff --git a/exec/exec.go b/exec/exec.go index 8018c19f4..e19bab64b 100644 --- a/exec/exec.go +++ b/exec/exec.go @@ -16,9 +16,9 @@ import ( "syscall" "time" + "github.com/juju/clock" "github.com/juju/errors" "github.com/juju/loggo" - "github.com/juju/utils/clock" ) var logger = loggo.GetLogger("juju.util.exec") diff --git a/exec/exec_test.go b/exec/exec_test.go index ed79ada25..12f73a936 100644 --- a/exec/exec_test.go +++ b/exec/exec_test.go @@ -13,7 +13,7 @@ import ( jc "github.com/juju/testing/checkers" gc "gopkg.in/check.v1" - "github.com/juju/utils/clock" + "github.com/juju/clock" "github.com/juju/utils/exec" ) diff --git a/limiter.go b/limiter.go index 6a1aefb4c..7db6689f2 100644 --- a/limiter.go +++ b/limiter.go @@ -8,7 +8,7 @@ import ( "math/rand" "time" - "github.com/juju/utils/clock" + "github.com/juju/clock" ) type empty struct{} diff --git a/limiter_test.go b/limiter_test.go index 8ad03bd85..6a183bbd7 100644 --- a/limiter_test.go +++ b/limiter_test.go @@ -7,6 +7,7 @@ import ( "fmt" "time" + "github.com/juju/clock/testclock" "github.com/juju/testing" jc "github.com/juju/testing/checkers" gc "gopkg.in/check.v1" @@ -81,7 +82,7 @@ func (*limiterSuite) TestAcquireWaitBlocksUntilRelease(c *gc.C) { } func (*limiterSuite) TestAcquirePauses(c *gc.C) { - clk := testing.NewClock(time.Now()) + clk := testclock.NewClock(time.Now()) l := utils.NewLimiterWithPause(2, 10*time.Millisecond, 20*time.Millisecond, clk) acquired := make(chan bool, 1) start := make(chan bool, 0) diff --git a/ssh/run.go b/ssh/run.go index a820b93e0..6e95b3306 100644 --- a/ssh/run.go +++ b/ssh/run.go @@ -10,8 +10,8 @@ import ( "syscall" "time" + "github.com/juju/clock" "github.com/juju/errors" - "github.com/juju/utils/clock" utilexec "github.com/juju/utils/exec" ) diff --git a/ssh/ssh_gocrypto.go b/ssh/ssh_gocrypto.go index 2cef54f26..3fe32bf3c 100644 --- a/ssh/ssh_gocrypto.go +++ b/ssh/ssh_gocrypto.go @@ -17,10 +17,10 @@ import ( "sync" "time" + "github.com/juju/clock" "github.com/juju/errors" "github.com/juju/mutex" "github.com/juju/utils" - "github.com/juju/utils/clock" "golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh/knownhosts" "golang.org/x/crypto/ssh/terminal" diff --git a/timer.go b/timer.go index 6b32f09df..6f8b7ee4c 100644 --- a/timer.go +++ b/timer.go @@ -8,7 +8,7 @@ import ( "math/rand" "time" - "github.com/juju/utils/clock" + "github.com/juju/clock" ) // Countdown implements a timer that will call a provided function. diff --git a/timer_test.go b/timer_test.go index 1ec957393..3bc1d72b8 100644 --- a/timer_test.go +++ b/timer_test.go @@ -10,10 +10,10 @@ import ( gc "gopkg.in/check.v1" + "github.com/juju/clock" "github.com/juju/testing" jc "github.com/juju/testing/checkers" "github.com/juju/utils" - "github.com/juju/utils/clock" ) type TestStdTimer struct {