podman

Форк
0
/
notifyproxy_test.go 
63 строки · 1.4 Кб
1
//go:build !windows
2

3
package notifyproxy
4

5
import (
6
	"testing"
7
	"time"
8

9
	"github.com/coreos/go-systemd/v22/daemon"
10
	"github.com/stretchr/testify/require"
11
)
12

13
// Helper function to send the specified message over the socket of the proxy.
14
func sendMessage(t *testing.T, proxy *NotifyProxy, message string) {
15
	err := SendMessage(proxy.SocketPath(), message)
16
	require.NoError(t, err)
17
}
18

19
func TestNotifyProxy(t *testing.T) {
20
	proxy, err := New("")
21
	require.NoError(t, err)
22
	require.FileExists(t, proxy.SocketPath())
23
	require.NoError(t, proxy.Close())
24
	require.NoFileExists(t, proxy.SocketPath())
25
}
26

27
func TestWaitAndClose(t *testing.T) {
28
	proxy, err := New("")
29
	require.NoError(t, err)
30
	require.FileExists(t, proxy.SocketPath())
31

32
	ch := make(chan error)
33
	defer func() {
34
		err := proxy.Close()
35
		require.NoError(t, err, "proxy should close successfully")
36
	}()
37
	go func() {
38
		ch <- proxy.Wait()
39
	}()
40

41
	sendMessage(t, proxy, "foo\n")
42
	time.Sleep(250 * time.Millisecond)
43
	select {
44
	case err := <-ch:
45
		t.Fatalf("Should still be waiting but received %v", err)
46
	default:
47
	}
48

49
	sendMessage(t, proxy, daemon.SdNotifyReady+"\nsomething else\n")
50
	done := func() bool {
51
		for i := 0; i < 10; i++ {
52
			select {
53
			case err := <-ch:
54
				require.NoError(t, err, "Waiting should succeed")
55
				return true
56
			default:
57
				time.Sleep(time.Duration(i*250) * time.Millisecond)
58
			}
59
		}
60
		return false
61
	}()
62
	require.True(t, done, "READY MESSAGE SHOULD HAVE ARRIVED")
63
}
64

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.