-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmonitor_test.go
81 lines (66 loc) · 1.64 KB
/
monitor_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package main
import (
"errors"
"os"
"testing"
"time"
)
type DummyDevicePlugin struct {
IBasicDevicePlugin
startError error
}
func (d *DummyDevicePlugin) Start() error {
return d.startError
}
func (*DummyDevicePlugin) Stop() {
}
func TestNoChangeOfStateAfterPluginFailsToStart(t *testing.T) {
nepm := &NitroEnclavesPluginMonitor{
devicePlugin: &DummyDevicePlugin{startError: errors.New("Some failure")},
}
nepm.setState(PluginIdle)
run(nepm)
if nepm.state() != PluginIdle {
t.Fatal("Expected the state = PluginIdle, but got ", nepm.state())
t.FailNow()
}
}
// Whenever the Kubelet socket is recreated, the plugin
// needs a restart.
func TestIntegrationValidatePluginNeedsARestart(t *testing.T) {
dp := "/tmp/"
ksn := dp + "dummy.domain.socket"
nepm := &NitroEnclavesPluginMonitor{
devicePlugin: &DummyDevicePlugin{},
devicePluginPath: dp,
kubeletSocketName: ksn,
}
// Remove the dummy socket file if exists
os.Remove(ksn)
result := nepm.Init()
if result != nil {
t.Fatal("Error while initializing plugin monitor.")
t.FailNow()
}
nepm.setState(PluginRunning)
go run(nepm)
// Reschedule
time.Sleep(100 * time.Millisecond)
// Create a dummy socket file
fdesc, _ := os.Create(ksn)
fdesc.Close()
defer os.Remove(ksn)
// Wait for the monitor state to change.
for i := 0; i < 10; i++ {
if nepm.state() == PluginRestarting {
break
}
time.Sleep(200 * time.Millisecond)
}
if nepm.state() != PluginRestarting {
t.Fatal("Socket file is generated, but the plugin didn't restart!")
t.FailNow()
}
}