From f0fb148fffe9e78068f0944b1328de83393c7a30 Mon Sep 17 00:00:00 2001 From: Mihai Todor Date: Sun, 4 Nov 2018 17:28:57 +0000 Subject: [PATCH] Update github.com/relistan/go-director --- Gopkg.lock | 184 ++++++++++++++++-- .../github.com/relistan/go-director/.travis | 13 ++ .../github.com/relistan/go-director/README.md | 24 ++- .../relistan/go-director/director.go | 33 ++-- .../relistan/go-director/director_test.go | 28 ++- 5 files changed, 238 insertions(+), 44 deletions(-) create mode 100644 vendor/github.com/relistan/go-director/.travis diff --git a/Gopkg.lock b/Gopkg.lock index e4de28e1..040e043f 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -3,258 +3,416 @@ [[projects]] branch = "master" + digest = "1:6978a38432a017763a148afbc7ce6491734b54292af7d3e969d84d2e9dd242e2" name = "github.com/Azure/go-ansiterm" - packages = [".","winterm"] + packages = [ + ".", + "winterm", + ] + pruneopts = "" revision = "d6e3b3328b783f23731bc4d058875b0371ff8109" [[projects]] + digest = "1:c9c336ca4936411a991d81f976dac8abf277ac7fd9d1c8ef706e94fc7948a0f7" name = "github.com/Microsoft/go-winio" packages = ["."] + pruneopts = "" revision = "78439966b38d69bf38227fbf57ac8a6fee70f69a" version = "v0.4.5" [[projects]] branch = "master" + digest = "1:6308de642ba0dd9a8904eec8f857a9591c4fd40958dc763ec8369a08f337b2fd" name = "github.com/Nitro/memberlist" packages = ["."] + pruneopts = "" revision = "cfac2b5cf519ec17fd0704afe1f80b9d7df2d60e" [[projects]] branch = "master" + digest = "1:3721a10686511b80c052323423f0de17a8c06d417dbdd3b392b1578432a33aae" name = "github.com/Nvveen/Gotty" packages = ["."] + pruneopts = "" revision = "cd527374f1e5bff4938207604a14f2e38a9cf512" [[projects]] branch = "master" + digest = "1:a74730e052a45a3fab1d310fdef2ec17ae3d6af16228421e238320846f2aaec8" name = "github.com/alecthomas/template" - packages = [".","parse"] + packages = [ + ".", + "parse", + ] + pruneopts = "" revision = "a0175ee3bccc567396460bf5acd36800cb10c49c" [[projects]] branch = "master" + digest = "1:8483994d21404c8a1d489f6be756e25bfccd3b45d65821f25695577791a08e68" name = "github.com/alecthomas/units" packages = ["."] + pruneopts = "" revision = "2efee857e7cfd4f3d0138cc3cbb1b4966962b93a" [[projects]] branch = "master" + digest = "1:524acf31ff1a13529dfe75b3ab2bd5637b7c90c4697756a5cd19564034b7ba90" name = "github.com/armon/go-metrics" packages = ["."] + pruneopts = "" revision = "7aa49fde808223f8dadfdbfd3a20ff6c19e5f9ec" [[projects]] branch = "master" + digest = "1:b27271ab7b32281fd2709830b0cc38294e1855e97aa5d729a5c1d79e8ad3ecaf" name = "github.com/containerd/continuity" packages = ["pathdriver"] + pruneopts = "" revision = "0cf103d319cc2d7efe085224094f466d1f8b9640" [[projects]] + digest = "1:c5808846facb26eb8ba4dea7b886c588af06a7e5cea02606cd855699be0fb1da" name = "github.com/docker/docker" - packages = ["api/types","api/types/blkiodev","api/types/container","api/types/filters","api/types/mount","api/types/network","api/types/registry","api/types/strslice","api/types/swarm","api/types/swarm/runtime","api/types/versions","opts","pkg/archive","pkg/fileutils","pkg/homedir","pkg/idtools","pkg/ioutils","pkg/jsonmessage","pkg/longpath","pkg/mount","pkg/pools","pkg/stdcopy","pkg/system","pkg/term","pkg/term/windows"] + packages = [ + "api/types", + "api/types/blkiodev", + "api/types/container", + "api/types/filters", + "api/types/mount", + "api/types/network", + "api/types/registry", + "api/types/strslice", + "api/types/swarm", + "api/types/swarm/runtime", + "api/types/versions", + "opts", + "pkg/archive", + "pkg/fileutils", + "pkg/homedir", + "pkg/idtools", + "pkg/ioutils", + "pkg/jsonmessage", + "pkg/longpath", + "pkg/mount", + "pkg/pools", + "pkg/stdcopy", + "pkg/system", + "pkg/term", + "pkg/term/windows", + ] + pruneopts = "" revision = "fe8aac6f5ae413a967adb0adad0b54abdfb825c4" [[projects]] + digest = "1:a5ecc2e70260a87aa263811281465a5effcfae8a54bac319cee87c4625f04d63" name = "github.com/docker/go-connections" packages = ["nat"] + pruneopts = "" revision = "3ede32e2033de7505e6500d6c868c2b9ed9f169d" version = "v0.3.0" [[projects]] + digest = "1:a406cae5eda48c01f8171bd47beb038751393f25ac06774ce04f9d6b0b703f17" name = "github.com/docker/go-units" packages = ["."] + pruneopts = "" revision = "0dadbb0345b35ec7ef35e228dabb8de89a65bf52" version = "v0.3.2" [[projects]] + digest = "1:4aace94ccef304a40e76fdc0959453fbb2451f12599bf5b556c1ff42c20be681" name = "github.com/fsouza/go-dockerclient" packages = ["."] + pruneopts = "" revision = "2ff310040c161b75fa19fb9b287a90a6e03c0012" version = "1.1" [[projects]] + digest = "1:70a80170917a15e1ff02faab5f9e716e945e0676e86599ba144d38f96e30c3bf" name = "github.com/gogo/protobuf" packages = ["proto"] + pruneopts = "" revision = "342cbe0a04158f6dcb03ca0079991a51a4248c02" version = "v0.5" [[projects]] branch = "master" + digest = "1:f1648d325872983461c860bc6641d8aaf8880f66856a5e0d9b39247556737d0d" name = "github.com/gopherjs/gopherjs" packages = ["js"] + pruneopts = "" revision = "444abdf920945de5d4a977b572bcc6c674d1e4eb" [[projects]] + digest = "1:20ed7daa9b3b38b6d1d39b48ab3fd31122be5419461470d0c28de3e121c93ecf" name = "github.com/gorilla/context" packages = ["."] + pruneopts = "" revision = "1ea25387ff6f684839d82767c1733ff4d4d15d0a" version = "v1.1" [[projects]] + digest = "1:a759b98c93c6dab29652eacd70cd7d0e88f02de8bc63051f787329966ec0a0ee" name = "github.com/gorilla/mux" packages = ["."] + pruneopts = "" revision = "7f08801859139f86dfafd1c296e2cba9a80d292e" version = "v1.6.0" [[projects]] branch = "master" + digest = "1:304c322b62533a48ac052ffee80f67087fce1bc07186cd4e610a1b0e77765836" name = "github.com/hashicorp/errwrap" packages = ["."] + pruneopts = "" revision = "7554cd9344cec97297fa6649b055a8c98c2a1e55" [[projects]] branch = "master" + digest = "1:6546c6d83de55dc47f3211e82d1e588baeb432e33859ccb1195ce52890466053" name = "github.com/hashicorp/go-immutable-radix" packages = ["."] + pruneopts = "" revision = "8aac2701530899b64bdea735a1de8da899815220" [[projects]] branch = "master" + digest = "1:6396690228a7560bf9247cb90e5ae9c797bd630b01e7d2acab430bbca9a1ecb3" name = "github.com/hashicorp/go-msgpack" packages = ["codec"] + pruneopts = "" revision = "fa3f63826f7c23912c15263591e65d54d080b458" [[projects]] branch = "master" + digest = "1:7660b6ee3fd92bcb9b19f5d359d3fbc8e853257d8a3d49e0424d00b6faa69cfd" name = "github.com/hashicorp/go-multierror" packages = ["."] + pruneopts = "" revision = "83588e72410abfbe4df460eeb6f30841ae47d4c4" [[projects]] branch = "master" + digest = "1:3486afd9dd072ec3e546b0028fa87b510f1dac3713bd0c477acb01c962b253a6" name = "github.com/hashicorp/go-sockaddr" packages = ["."] + pruneopts = "" revision = "9b4c5fa5b10a683339a270d664474b9f4aee62fc" [[projects]] branch = "master" + digest = "1:43987212a2f16bfacc1a286e9118f212d60c136ed53c6c9477c18921db53140b" name = "github.com/hashicorp/golang-lru" packages = ["simplelru"] + pruneopts = "" revision = "0a025b7e63adc15a622f29b0b2c4c3848243bbf6" [[projects]] + digest = "1:d8ead22d381cfed54d53be7d935eb0f9f2b75889a4fb595802844b805dc13b87" name = "github.com/jtolds/gls" packages = ["."] + pruneopts = "" revision = "77f18212c9c7edc9bd6a33d383a7b545ce62f064" version = "v4.2.1" [[projects]] + digest = "1:b60a24f942c7031ece6c48bcab0b683c7d3d6aa9fd17e21459d9ae604da258fa" name = "github.com/kelseyhightower/envconfig" packages = ["."] + pruneopts = "" revision = "f611eb38b3875cc3bd991ca91c51d06446afa14c" version = "v1.3.0" [[projects]] branch = "master" + digest = "1:ee75704d55e802aa72829f54b5d35e0a2b774a194da4a4bd04bbca9eb794c160" name = "github.com/miekg/dns" - packages = [".","internal/socket"] + packages = [ + ".", + "internal/socket", + ] + pruneopts = "" revision = "be5ae6ca7ac994584d2e30167737687f1c1ded8e" [[projects]] branch = "master" + digest = "1:bdbab69b21c3c0409e24b3ec53a9bdf2c2dbc3d80bbe73e8d0c8ebc47f660e3d" name = "github.com/mohae/deepcopy" packages = ["."] + pruneopts = "" revision = "c48cc78d482608239f6c4c92a4abd87eb8761c90" [[projects]] + digest = "1:5d9b668b0b4581a978f07e7d2e3314af18eb27b3fb5d19b70185b7c575723d11" name = "github.com/opencontainers/go-digest" packages = ["."] + pruneopts = "" revision = "279bed98673dd5bef374d3b6e4b09e2af76183bf" version = "v1.0.0-rc1" [[projects]] + digest = "1:f26c8670b11e29a49c8e45f7ec7f2d5bac62e8fd4e3c0ae1662baa4a697f984a" name = "github.com/opencontainers/image-spec" - packages = ["specs-go","specs-go/v1"] + packages = [ + "specs-go", + "specs-go/v1", + ] + pruneopts = "" revision = "d60099175f88c47cd379c4738d158884749ed235" version = "v1.0.1" [[projects]] + digest = "1:fa19ddee0e5ee5951a6a450a4b6ec635a42957f86bfc87d9d778eeee04ad2036" name = "github.com/opencontainers/runc" - packages = ["libcontainer/system","libcontainer/user"] + packages = [ + "libcontainer/system", + "libcontainer/user", + ] + pruneopts = "" revision = "baf6536d6259209c3edfa2b22237af82942d3dfa" version = "v0.1.1" [[projects]] + digest = "1:7365acd48986e205ccb8652cc746f09c8b7876030d53710ea6ef7d0bd0dcd7ca" name = "github.com/pkg/errors" packages = ["."] + pruneopts = "" revision = "645ef00459ed84a119197bfb8d8205042c6df63d" version = "v0.8.0" [[projects]] branch = "master" + digest = "1:c7743ce9b306ce7f2b79aff7192332aef99399ef0a050ec7fe6231e3516826bf" name = "github.com/pquerna/ffjson" - packages = ["ffjson","fflib/v1","fflib/v1/internal"] + packages = [ + "ffjson", + "fflib/v1", + "fflib/v1/internal", + ] + pruneopts = "" revision = "d49c2bc1aa135aad0c6f4fc2056623ec78f5d5ac" [[projects]] branch = "master" + digest = "1:f88fea3686d82587d8e1dfe6499c3a51fcc6a99675c9a3e63d5afcc85fe45025" name = "github.com/relistan/go-director" packages = ["."] - revision = "9273dae8c839a114aa4472165f84e057d5b12e09" + pruneopts = "" + revision = "5f56787d973127a1c878fb5cff31ff100846714c" [[projects]] branch = "master" + digest = "1:6ee36f2cea425916d81fdaaf983469fc18f91b3cf090cfe90fa0a9d85b8bfab7" name = "github.com/sean-/seed" packages = ["."] + pruneopts = "" revision = "e2103e2c35297fb7e17febb81e49b312087a2372" [[projects]] + digest = "1:3ac248add5bb40a3c631c5334adcd09aa72d15af2768a5bc0274084ea7b2e5ba" name = "github.com/sirupsen/logrus" packages = ["."] + pruneopts = "" revision = "f006c2ac4710855cf0f916dd6b77acf6b048dc6e" version = "v1.0.3" [[projects]] + digest = "1:fbf54e9f8cf26ea8e66dc1e0cc615663efa95af8c8d806125ff7f7bb7311b9e0" name = "github.com/smartystreets/assertions" - packages = [".","internal/go-render/render","internal/oglematchers"] + packages = [ + ".", + "internal/go-render/render", + "internal/oglematchers", + ] + pruneopts = "" revision = "ff1918e1e5a13a74014644ae7c1e0ba2f791364d" version = "1.8.0" [[projects]] + digest = "1:dd808f0f1628ff85a1b54424d3e6a61c54a87353d5063b9b5c82ad360f0346d5" name = "github.com/smartystreets/goconvey" - packages = ["convey","convey/gotest","convey/reporting"] + packages = [ + "convey", + "convey/gotest", + "convey/reporting", + ] + pruneopts = "" revision = "9e8dc3f972df6c8fcc0375ef492c24d0bb204857" version = "1.6.3" [[projects]] branch = "master" + digest = "1:f6a006d27619a4d93bf9b66fe1999b8c8d1fa62bdc63af14f10fbe6fcaa2aa1a" name = "golang.org/x/crypto" packages = ["ssh/terminal"] + pruneopts = "" revision = "9f005a07e0d31d45e6656d241bb5c0f2efd4bc94" [[projects]] branch = "master" + digest = "1:1285570ced192ee4703ca44573a4eaf19b5a0895af56f9db2210b171eefd2a41" name = "golang.org/x/net" - packages = ["context","context/ctxhttp"] + packages = [ + "context", + "context/ctxhttp", + ] + pruneopts = "" revision = "c7086645de248775cbf2373cf5ca4d2fa664b8c1" [[projects]] branch = "master" + digest = "1:eaa0459091ac9b59beb42b5f11af13519d856ccd12d3871b5c4c9de230611316" name = "golang.org/x/sys" - packages = ["unix","windows"] + packages = [ + "unix", + "windows", + ] + pruneopts = "" revision = "82aafbf43bf885069dc71b7e7c2f9d7a614d47da" [[projects]] + digest = "1:7dc69d1597e4773ec5f64e5c078d55f0f011bb05ec0435346d0649ad978a23fd" name = "gopkg.in/alecthomas/kingpin.v2" packages = ["."] + pruneopts = "" revision = "1087e65c9441605df944fb12c33f0fe7072d18ca" version = "v2.2.5" [[projects]] branch = "v1" + digest = "1:067954126f4f0f7ac513233125d68ff932cce03fc73ebba4dee905926ca3f4c4" name = "gopkg.in/jarcoal/httpmock.v1" packages = ["."] + pruneopts = "" revision = "cf52904a3cf0f78f199ecade6a6df8e245d5b25a" [[projects]] + digest = "1:92b5b000c6c4acbb692162d247b4e9f5c7485aac6be5396df63601e80139b08f" name = "gopkg.in/relistan/rubberneck.v1" packages = ["."] + pruneopts = "" revision = "4c696efeea6013864af139313af7c7492458fbbf" version = "v1.0.1" [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "1f81c9a744228d3f94eb883f0e11dcee283a58e964870fefcb49c11da988c87c" + input-imports = [ + "github.com/Nitro/memberlist", + "github.com/armon/go-metrics", + "github.com/fsouza/go-dockerclient", + "github.com/gorilla/mux", + "github.com/kelseyhightower/envconfig", + "github.com/mohae/deepcopy", + "github.com/pquerna/ffjson/ffjson", + "github.com/pquerna/ffjson/fflib/v1", + "github.com/relistan/go-director", + "github.com/sirupsen/logrus", + "github.com/smartystreets/goconvey/convey", + "gopkg.in/alecthomas/kingpin.v2", + "gopkg.in/jarcoal/httpmock.v1", + "gopkg.in/relistan/rubberneck.v1", + ] solver-name = "gps-cdcl" solver-version = 1 diff --git a/vendor/github.com/relistan/go-director/.travis b/vendor/github.com/relistan/go-director/.travis new file mode 100644 index 00000000..9097b903 --- /dev/null +++ b/vendor/github.com/relistan/go-director/.travis @@ -0,0 +1,13 @@ +language: go + +go: + - 1.11.x + +sudo: required + +install: + - curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $GOPATH/bin v1.10.2 + +script: + - golangci-lint run + - go test -v -race --timeout 1m \ No newline at end of file diff --git a/vendor/github.com/relistan/go-director/README.md b/vendor/github.com/relistan/go-director/README.md index ec627dfb..a7a19c79 100644 --- a/vendor/github.com/relistan/go-director/README.md +++ b/vendor/github.com/relistan/go-director/README.md @@ -1,4 +1,5 @@ [![godoc here](https://img.shields.io/badge/godoc-here-blue.svg)](http://godoc.org/github.com/relistan/go-director) +[![Build Status](https://travis-ci.org/relistan/go-director.svg?branch=master)](https://travis-ci.org/relistan/go-director) Director ======== @@ -32,15 +33,26 @@ if err != nil { } ``` -Details and Motivation ----------------------- +The Problem This Solves +----------------------- + +Testing functions that are meant to run in background goroutines can be tricky. +You might have to wait for a period of time to let it run on a timed loop. You +might have to trigger the function from inside the test rather than from where +it would naturally run. Then there is the problem of stopping it between tests +if you need to reset state. Or knowing that it completed. These are all +solvable. Depending on your scenario it might not even be complex. But wouldn't +it be nice if you could rely on doing this the same way everywhere? That's +what this library attempts to do. + +Example Usage +------------- + The core interface for the package is the `Looper`. Two `Looper` implementations are currently included, a `TimedLooper` whichs runs the loop on a specified interval, and a `FreeLooper` which runs the loop as quickly as -possible. - -This is really a convenience package to prevent writing boilerplate over and -over, and to make it easy to test your code. +possible. You get some nice fucntions to control how they behave. Let's take a +look at how you might use it. The `Looper` interface looks like this: diff --git a/vendor/github.com/relistan/go-director/director.go b/vendor/github.com/relistan/go-director/director.go index 1c5ee630..52123bff 100644 --- a/vendor/github.com/relistan/go-director/director.go +++ b/vendor/github.com/relistan/go-director/director.go @@ -28,11 +28,6 @@ type Looper interface { // If you pass in a DoneChan at creation time, it will send a nil on the // channel when the loop has completed successfully or an error if the loop // resulted in an error condition. -// -// If you pass in a quitChan it can be used to tell the loop to exit on completion -// of the next iteration. Using both Done and Quit channels allows full external -// control of the loop. - type TimedLooper struct { Count int Interval time.Duration @@ -41,8 +36,6 @@ type TimedLooper struct { Immediate bool } -// Same as a TimedLooper, except it will execute an iteration of the loop -// immediately after calling on Loop() (as opposed to waiting until the tick) func NewTimedLooper(count int, interval time.Duration, done chan error) *TimedLooper { return &TimedLooper{ Count: count, @@ -53,6 +46,8 @@ func NewTimedLooper(count int, interval time.Duration, done chan error) *TimedLo } } +// Same as a TimedLooper, except it will execute an iteration of the loop +// immediately after calling on Loop() (as opposed to waiting until the tick) func NewImmediateTimedLooper(count int, interval time.Duration, done chan error) *TimedLooper { return &TimedLooper{ Count: count, @@ -82,7 +77,6 @@ func (l *TimedLooper) Loop(fn func() error) { i := 0 var stop bool - stopFunc := func(err error) { l.Done(err) stop = true @@ -104,13 +98,6 @@ func (l *TimedLooper) Loop(fn func() error) { return } } - - select { - case <-l.quitChan: - stopFunc(nil) - return - default: - } } // Immediatelly run our function if we've been instantiated via @@ -119,13 +106,23 @@ func (l *TimedLooper) Loop(fn func() error) { runIteration() } - ticks := time.Tick(l.Interval) - for range ticks { + ticker := time.NewTicker(l.Interval) + defer ticker.Stop() + for { + // The execution loop needs to be able to stop automatically + // after l.Count iterations. It does so when runIteration + // invokes stopFunc, which sets `stop` to false. if stop { break } - runIteration() + select { + case <-ticker.C: + runIteration() + case <-l.quitChan: + stopFunc(nil) + break + } } } diff --git a/vendor/github.com/relistan/go-director/director_test.go b/vendor/github.com/relistan/go-director/director_test.go index 2bd14990..14909859 100644 --- a/vendor/github.com/relistan/go-director/director_test.go +++ b/vendor/github.com/relistan/go-director/director_test.go @@ -40,7 +40,7 @@ func Test_TimedLooper(t *testing.T) { count := 0 looper.Count = 5 go looper.Loop(func() error { count++; return nil }) - looper.Wait() + So(looper.Wait(), ShouldBeNil) So(count, ShouldEqual, 5) }) @@ -59,7 +59,10 @@ func Test_TimedLooper(t *testing.T) { looper.Quit() So(looper.Wait(), ShouldBeNil) - So(count, ShouldBeLessThan, 2) + + previousCount := count + time.Sleep(1 * time.Millisecond) + So(count, ShouldEqual, previousCount) }) }) } @@ -96,7 +99,7 @@ func Test_FreeLooper(t *testing.T) { Convey("The loop executes the function", func() { run := false go looper.Loop(func() error { run = true; return nil }) - looper.Wait() + So(looper.Wait(), ShouldBeNil) So(run, ShouldBeTrue) }) @@ -105,7 +108,7 @@ func Test_FreeLooper(t *testing.T) { count := 0 looper.Count = 5 go looper.Loop(func() error { count++; return nil }) - looper.Wait() + So(looper.Wait(), ShouldBeNil) So(count, ShouldEqual, 5) }) @@ -124,7 +127,10 @@ func Test_FreeLooper(t *testing.T) { looper.Quit() So(looper.Wait(), ShouldBeNil) - So(count, ShouldBeLessThan, 2) + + previousCount := count + time.Sleep(1 * time.Millisecond) + So(count, ShouldEqual, previousCount) }) }) } @@ -144,7 +150,10 @@ func ExampleTimedLooper() { } go runner(looper) - looper.Wait() + err := looper.Wait() + if err != nil { + fmt.Printf("I got an error: %s\n", err.Error()) + } // Output: // 0 @@ -170,8 +179,13 @@ func ExampleTimedLooper_Quit() { } go runner(looper) + // Wait for one run to complete + time.Sleep(90 * time.Millisecond) looper.Quit() - looper.Wait() + err := looper.Wait() + if err != nil { + fmt.Printf("I got an error: %s\n", err.Error()) + } // Output: // 0