diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-11-15 18:31:37 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-15 18:31:37 +0100 |
commit | 47eaf23039d5a1352352ac1b33196b8344065632 (patch) | |
tree | fbf01bbb1c00fe5d46bca2b693a8e125ed30b694 /pkg/bindings/test/connection_test.go | |
parent | 9eaa6f4566eff75f5710c48ae0ba3d98840a50a9 (diff) | |
parent | 5df883e87d7d4faec24c53c89bab3255057de0bc (diff) | |
download | podman-47eaf23039d5a1352352ac1b33196b8344065632.tar.gz podman-47eaf23039d5a1352352ac1b33196b8344065632.tar.bz2 podman-47eaf23039d5a1352352ac1b33196b8344065632.zip |
Merge pull request #12300 from WanzenBug/fix-bindings-context
bindings: reuse context for API requests
Diffstat (limited to 'pkg/bindings/test/connection_test.go')
-rw-r--r-- | pkg/bindings/test/connection_test.go | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/pkg/bindings/test/connection_test.go b/pkg/bindings/test/connection_test.go new file mode 100644 index 000000000..561cf32b5 --- /dev/null +++ b/pkg/bindings/test/connection_test.go @@ -0,0 +1,68 @@ +package test_bindings + +import ( + "context" + "time" + + "github.com/containers/podman/v3/pkg/bindings/containers" + "github.com/containers/podman/v3/pkg/bindings/system" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + "github.com/onsi/gomega/gexec" +) + +var _ = Describe("Podman connection", func() { + var ( + bt *bindingTest + s *gexec.Session + ) + + BeforeEach(func() { + bt = newBindingTest() + bt.RestoreImagesFromCache() + s = bt.startAPIService() + time.Sleep(1 * time.Second) + err := bt.NewConnection() + Expect(err).To(BeNil()) + }) + + AfterEach(func() { + s.Kill() + bt.cleanup() + }) + + It("request on cancelled context results in error", func() { + ctx, cancel := context.WithCancel(bt.conn) + cancel() + _, err := system.Version(ctx, nil) + Expect(err).To(MatchError(ctx.Err())) + }) + + It("cancel request in flight reports cancelled context", func() { + var name = "top" + _, err := bt.RunTopContainer(&name, nil) + Expect(err).To(BeNil()) + + errChan := make(chan error) + ctx, cancel := context.WithCancel(bt.conn) + + go func() { + defer close(errChan) + _, err := containers.Wait(ctx, name, nil) + errChan <- err + }() + + // Wait for the goroutine to fire the request + time.Sleep(1 * time.Second) + + cancel() + + select { + case err, ok := <-errChan: + Expect(ok).To(BeTrue()) + Expect(err).To(MatchError(ctx.Err())) + case <-time.NewTimer(1 * time.Second).C: + Fail("cancelled request did not return in less than 1 second") + } + }) +}) |