mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-29 21:29:24 +00:00
e2e: accept context from Ginkgo
Every ginkgo callback should return immediately when a timeout occurs or the
test run manually gets aborted with CTRL-C. To do that, they must take a ctx
parameter and pass it through to all code which might block.
This is a first automated step towards that: the additional parameter got added
with
sed -i 's/\(framework.ConformanceIt\|ginkgo.It\)\(.*\)func() {$/\1\2func(ctx context.Context) {/' \
$(git grep -l -e framework.ConformanceIt -e ginkgo.It )
$GOPATH/bin/goimports -w $(git status | grep modified: | sed -e 's/.* //')
log_test.go was left unchanged.
This commit is contained in:
@@ -57,7 +57,7 @@ ginkgo.AfterEach(func() {
|
||||
# Do something with f.ClientSet.
|
||||
}
|
||||
|
||||
ginkgo.It("test something", func() {
|
||||
ginkgo.It("test something", func(ctx context.Context) {
|
||||
# The actual test.
|
||||
})
|
||||
```
|
||||
|
||||
@@ -22,6 +22,7 @@ limitations under the License.
|
||||
package cleanup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"regexp"
|
||||
"testing"
|
||||
@@ -77,7 +78,7 @@ var _ = ginkgo.Describe("e2e", func() {
|
||||
framework.Logf("after #2")
|
||||
})
|
||||
|
||||
ginkgo.It("works", func() {
|
||||
ginkgo.It("works", func(ctx context.Context) {
|
||||
// DeferCleanup invokes in first-in-last-out order
|
||||
ginkgo.DeferCleanup(func() {
|
||||
framework.Logf("cleanup last")
|
||||
|
||||
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
package pod_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -52,11 +53,11 @@ import (
|
||||
// This must be line #52.
|
||||
|
||||
var _ = ginkgo.Describe("pod", func() {
|
||||
ginkgo.It("not found", func() {
|
||||
ginkgo.It("not found", func(ctx context.Context) {
|
||||
framework.ExpectNoError(e2epod.WaitTimeoutForPodRunningInNamespace(clientSet, "no-such-pod", "default", timeout /* no explanation here to cover that code path */))
|
||||
})
|
||||
|
||||
ginkgo.It("not running", func() {
|
||||
ginkgo.It("not running", func(ctx context.Context) {
|
||||
framework.ExpectNoError(e2epod.WaitTimeoutForPodRunningInNamespace(clientSet, podName, podNamespace, timeout), "wait for pod %s running", podName /* tests printf formatting */)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
package skipper_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"testing"
|
||||
|
||||
@@ -50,7 +51,7 @@ import (
|
||||
// This must be line #50.
|
||||
|
||||
var _ = ginkgo.Describe("e2e", func() {
|
||||
ginkgo.It("skips", func() {
|
||||
ginkgo.It("skips", func(ctx context.Context) {
|
||||
e2eskipper.Skipf("skipping %d, %d, %d", 1, 3, 4)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user