mirror of
https://github.com/containers/podman.git
synced 2025-08-06 19:44:14 +08:00

As outlined in #16076, a subsequent BARRIER *may* follow the READY message sent by a container. To correctly imitate the behavior of systemd's NOTIFY_SOCKET, the notify proxies span up by `kube play` must hence process messages for the entirety of the workload. We know that the workload is done and that all containers and pods have exited when the service container exits. Hence, all proxies are closed at that time. The above changes imply that Podman runs for the entirety of the workload and will henceforth act as the MAINPID when running inside of systemd. Prior to this change, the service container acted as the MAINPID which is now not possible anymore; Podman would be killed immediately on exit of the service container and could not clean up. The kube template now correctly transitions to in-active instead of failed in systemd. Fixes: #16076 Fixes: #16515 Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
62 lines
1.4 KiB
Go
62 lines
1.4 KiB
Go
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)
|
|
defer func() {
|
|
err := proxy.Close()
|
|
require.NoError(t, err, "proxy should close successfully")
|
|
}()
|
|
go func() {
|
|
ch <- proxy.Wait()
|
|
}()
|
|
|
|
sendMessage(t, proxy, "foo\n")
|
|
time.Sleep(250 * time.Millisecond)
|
|
select {
|
|
case err := <-ch:
|
|
t.Fatalf("Should still be waiting but received %v", err)
|
|
default:
|
|
}
|
|
|
|
sendMessage(t, proxy, daemon.SdNotifyReady+"\nsomething else\n")
|
|
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")
|
|
}
|