aboutsummaryrefslogtreecommitdiff
path: root/pkg/systemd/notifyproxy/notifyproxy_test.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2022-08-11 15:44:55 +0000
committerGitHub <noreply@github.com>2022-08-11 15:44:55 +0000
commit92bbae40de3c48ee6b4692ab9e4d7cc14db242bb (patch)
tree89df1d0983bbb2c978e54e48d377f316e0b44485 /pkg/systemd/notifyproxy/notifyproxy_test.go
parent7af523ea5af8ba8ad61cd4b81a1494a42ac7b479 (diff)
parent79e21b5b162d3c2d3fb274b20bfe180c15284893 (diff)
downloadpodman-92bbae40de3c48ee6b4692ab9e4d7cc14db242bb.tar.gz
podman-92bbae40de3c48ee6b4692ab9e4d7cc14db242bb.tar.bz2
podman-92bbae40de3c48ee6b4692ab9e4d7cc14db242bb.zip
Merge pull request #15248 from vrothberg/RUN-1606
kube play: sd-notify integration
Diffstat (limited to 'pkg/systemd/notifyproxy/notifyproxy_test.go')
-rw-r--r--pkg/systemd/notifyproxy/notifyproxy_test.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/pkg/systemd/notifyproxy/notifyproxy_test.go b/pkg/systemd/notifyproxy/notifyproxy_test.go
new file mode 100644
index 000000000..edad95659
--- /dev/null
+++ b/pkg/systemd/notifyproxy/notifyproxy_test.go
@@ -0,0 +1,58 @@
+package notifyproxy
+
+import (
+ "testing"
+ "time"
+
+ "github.com/coreos/go-systemd/v22/daemon"
+ "github.com/stretchr/testify/require"
+)
+
+// Helper function to send the specified message over the socket of the proxy.
+func sendMessage(t *testing.T, proxy *NotifyProxy, message string) {
+ err := SendMessage(proxy.SocketPath(), message)
+ require.NoError(t, err)
+}
+
+func TestNotifyProxy(t *testing.T) {
+ proxy, err := New("")
+ require.NoError(t, err)
+ require.FileExists(t, proxy.SocketPath())
+ require.NoError(t, proxy.close())
+ require.NoFileExists(t, proxy.SocketPath())
+}
+
+func TestWaitAndClose(t *testing.T) {
+ proxy, err := New("")
+ require.NoError(t, err)
+ require.FileExists(t, proxy.SocketPath())
+
+ ch := make(chan error)
+
+ go func() {
+ ch <- proxy.WaitAndClose()
+ }()
+
+ sendMessage(t, proxy, "foo\n")
+ time.Sleep(250 * time.Millisecond)
+ select {
+ case err := <-ch:
+ t.Fatalf("Should stil be waiting but received %v", err)
+ default:
+ }
+
+ sendMessage(t, proxy, daemon.SdNotifyReady+"\nsomething else")
+ done := func() bool {
+ for i := 0; i < 10; i++ {
+ select {
+ case err := <-ch:
+ require.NoError(t, err, "Waiting should succeed")
+ return true
+ default:
+ time.Sleep(time.Duration(i*250) * time.Millisecond)
+ }
+ }
+ return false
+ }()
+ require.True(t, done, "READY MESSAGE SHOULD HAVE ARRIVED")
+}