[VOL-4290] Voltha go library updates for gRPC migration
Change-Id: I1aa2774beb6b7ed7419bc45aeb53fcae8a8ecda0
diff --git a/vendor/github.com/jonboulle/clockwork/.editorconfig b/vendor/github.com/jonboulle/clockwork/.editorconfig
new file mode 100644
index 0000000..4492e9f
--- /dev/null
+++ b/vendor/github.com/jonboulle/clockwork/.editorconfig
@@ -0,0 +1,12 @@
+root = true
+
+[*]
+charset = utf-8
+end_of_line = lf
+indent_size = 4
+indent_style = space
+insert_final_newline = true
+trim_trailing_whitespace = true
+
+[*.go]
+indent_style = tab
diff --git a/vendor/github.com/jonboulle/clockwork/.gitignore b/vendor/github.com/jonboulle/clockwork/.gitignore
index 010c242..00852bd 100644
--- a/vendor/github.com/jonboulle/clockwork/.gitignore
+++ b/vendor/github.com/jonboulle/clockwork/.gitignore
@@ -1,3 +1,5 @@
+/.idea/
+
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
diff --git a/vendor/github.com/jonboulle/clockwork/.travis.yml b/vendor/github.com/jonboulle/clockwork/.travis.yml
deleted file mode 100644
index aefda90..0000000
--- a/vendor/github.com/jonboulle/clockwork/.travis.yml
+++ /dev/null
@@ -1,5 +0,0 @@
-language: go
-go:
- - 1.3
-
-sudo: false
diff --git a/vendor/github.com/jonboulle/clockwork/README.md b/vendor/github.com/jonboulle/clockwork/README.md
index d43a6c7..cad6083 100644
--- a/vendor/github.com/jonboulle/clockwork/README.md
+++ b/vendor/github.com/jonboulle/clockwork/README.md
@@ -1,61 +1,80 @@
-clockwork
-=========
+# clockwork
-[![Build Status](https://travis-ci.org/jonboulle/clockwork.png?branch=master)](https://travis-ci.org/jonboulle/clockwork)
-[![godoc](https://godoc.org/github.com/jonboulle/clockwork?status.svg)](http://godoc.org/github.com/jonboulle/clockwork)
+[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge-flat.svg)](https://github.com/avelino/awesome-go#utilities)
-a simple fake clock for golang
+[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/jonboulle/clockwork/CI?style=flat-square)](https://github.com/jonboulle/clockwork/actions?query=workflow%3ACI)
+[![Go Report Card](https://goreportcard.com/badge/github.com/jonboulle/clockwork?style=flat-square)](https://goreportcard.com/report/github.com/jonboulle/clockwork)
+![Go Version](https://img.shields.io/badge/go%20version-%3E=1.11-61CFDD.svg?style=flat-square)
+[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white&style=flat-square)](https://pkg.go.dev/mod/github.com/jonboulle/clockwork)
-# Usage
+**A simple fake clock for Go.**
+
+
+## Usage
Replace uses of the `time` package with the `clockwork.Clock` interface instead.
For example, instead of using `time.Sleep` directly:
-```
-func my_func() {
+```go
+func myFunc() {
time.Sleep(3 * time.Second)
- do_something()
+ doSomething()
}
```
-inject a clock and use its `Sleep` method instead:
+Inject a clock and use its `Sleep` method instead:
-```
-func my_func(clock clockwork.Clock) {
+```go
+func myFunc(clock clockwork.Clock) {
clock.Sleep(3 * time.Second)
- do_something()
+ doSomething()
}
```
-Now you can easily test `my_func` with a `FakeClock`:
+Now you can easily test `myFunc` with a `FakeClock`:
-```
+```go
func TestMyFunc(t *testing.T) {
c := clockwork.NewFakeClock()
// Start our sleepy function
- my_func(c)
+ var wg sync.WaitGroup
+ wg.Add(1)
+ go func() {
+ myFunc(c)
+ wg.Done()
+ }()
- // Ensure we wait until my_func is sleeping
+ // Ensure we wait until myFunc is sleeping
c.BlockUntil(1)
- assert_state()
+ assertState()
// Advance the FakeClock forward in time
- c.Advance(3)
+ c.Advance(3 * time.Second)
- assert_state()
+ // Wait until the function completes
+ wg.Wait()
+
+ assertState()
}
```
and in production builds, simply inject the real clock instead:
-```
-my_func(clockwork.NewRealClock())
+
+```go
+myFunc(clockwork.NewRealClock())
```
See [example_test.go](example_test.go) for a full example.
+
# Credits
-clockwork is inspired by @wickman's [threaded fake clock](https://gist.github.com/wickman/3840816), and the [Golang playground](http://blog.golang.org/playground#Faking time)
+clockwork is inspired by @wickman's [threaded fake clock](https://gist.github.com/wickman/3840816), and the [Golang playground](https://blog.golang.org/playground#TOC_3.1.)
+
+
+## License
+
+Apache License, Version 2.0. Please see [License File](LICENSE) for more information.
diff --git a/vendor/github.com/jonboulle/clockwork/clockwork.go b/vendor/github.com/jonboulle/clockwork/clockwork.go
index 9ec96ed..1018051 100644
--- a/vendor/github.com/jonboulle/clockwork/clockwork.go
+++ b/vendor/github.com/jonboulle/clockwork/clockwork.go
@@ -11,6 +11,8 @@
After(d time.Duration) <-chan time.Time
Sleep(d time.Duration)
Now() time.Time
+ Since(t time.Time) time.Duration
+ NewTicker(d time.Duration) Ticker
}
// FakeClock provides an interface for a clock which can be
@@ -60,6 +62,14 @@
return time.Now()
}
+func (rc *realClock) Since(t time.Time) time.Duration {
+ return rc.Now().Sub(t)
+}
+
+func (rc *realClock) NewTicker(d time.Duration) Ticker {
+ return &realTicker{time.NewTicker(d)}
+}
+
type fakeClock struct {
sleepers []*sleeper
blockers []*blocker
@@ -87,7 +97,7 @@
defer fc.l.Unlock()
now := fc.time
done := make(chan time.Time, 1)
- if d.Nanoseconds() == 0 {
+ if d.Nanoseconds() <= 0 {
// special case - trigger immediately
done <- now
} else {
@@ -130,6 +140,22 @@
return t
}
+// Since returns the duration that has passed since the given time on the fakeClock
+func (fc *fakeClock) Since(t time.Time) time.Duration {
+ return fc.Now().Sub(t)
+}
+
+func (fc *fakeClock) NewTicker(d time.Duration) Ticker {
+ ft := &fakeTicker{
+ c: make(chan time.Time, 1),
+ stop: make(chan bool, 1),
+ clock: fc,
+ period: d,
+ }
+ ft.runTickThread()
+ return ft
+}
+
// Advance advances fakeClock to a new point in time, ensuring channels from any
// previous invocations of After are notified appropriately before returning
func (fc *fakeClock) Advance(d time.Duration) {
diff --git a/vendor/github.com/jonboulle/clockwork/go.mod b/vendor/github.com/jonboulle/clockwork/go.mod
new file mode 100644
index 0000000..4f4bb16
--- /dev/null
+++ b/vendor/github.com/jonboulle/clockwork/go.mod
@@ -0,0 +1,3 @@
+module github.com/jonboulle/clockwork
+
+go 1.13
diff --git a/vendor/github.com/jonboulle/clockwork/ticker.go b/vendor/github.com/jonboulle/clockwork/ticker.go
new file mode 100644
index 0000000..32b5d01
--- /dev/null
+++ b/vendor/github.com/jonboulle/clockwork/ticker.go
@@ -0,0 +1,72 @@
+package clockwork
+
+import (
+ "time"
+)
+
+// Ticker provides an interface which can be used instead of directly
+// using the ticker within the time module. The real-time ticker t
+// provides ticks through t.C which becomes now t.Chan() to make
+// this channel requirement definable in this interface.
+type Ticker interface {
+ Chan() <-chan time.Time
+ Stop()
+}
+
+type realTicker struct{ *time.Ticker }
+
+func (rt *realTicker) Chan() <-chan time.Time {
+ return rt.C
+}
+
+type fakeTicker struct {
+ c chan time.Time
+ stop chan bool
+ clock FakeClock
+ period time.Duration
+}
+
+func (ft *fakeTicker) Chan() <-chan time.Time {
+ return ft.c
+}
+
+func (ft *fakeTicker) Stop() {
+ ft.stop <- true
+}
+
+// runTickThread initializes a background goroutine to send the tick time to the ticker channel
+// after every period. Tick events are discarded if the underlying ticker channel does not have
+// enough capacity.
+func (ft *fakeTicker) runTickThread() {
+ nextTick := ft.clock.Now().Add(ft.period)
+ next := ft.clock.After(ft.period)
+ go func() {
+ for {
+ select {
+ case <-ft.stop:
+ return
+ case <-next:
+ // We send the time that the tick was supposed to occur at.
+ tick := nextTick
+ // Before sending the tick, we'll compute the next tick time and star the clock.After call.
+ now := ft.clock.Now()
+ // First, figure out how many periods there have been between "now" and the time we were
+ // supposed to have trigged, then advance over all of those.
+ skipTicks := (now.Sub(tick) + ft.period - 1) / ft.period
+ nextTick = nextTick.Add(skipTicks * ft.period)
+ // Now, keep advancing until we are past now. This should happen at most once.
+ for !nextTick.After(now) {
+ nextTick = nextTick.Add(ft.period)
+ }
+ // Figure out how long between now and the next scheduled tick, then wait that long.
+ remaining := nextTick.Sub(now)
+ next = ft.clock.After(remaining)
+ // Finally, we can actually send the tick.
+ select {
+ case ft.c <- tick:
+ default:
+ }
+ }
+ }
+ }()
+}