Skip to content

Commit 320e4e7

Browse files
committedSep 27, 2024··
adaptation: tests for runtime version, timeouts.
Add tests for passing runtime version and configured timeouts to plugins. Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
1 parent f86d982 commit 320e4e7

File tree

2 files changed

+94
-3
lines changed

2 files changed

+94
-3
lines changed
 

‎pkg/adaptation/adaptation_suite_test.go

+66
Original file line numberDiff line numberDiff line change
@@ -1869,6 +1869,72 @@ var _ = Describe("Unsolicited container update requests", func() {
18691869
})
18701870
})
18711871

1872+
var _ = Describe("Plugin configuration request", func() {
1873+
var (
1874+
s = &Suite{}
1875+
)
1876+
1877+
AfterEach(func() {
1878+
s.Cleanup()
1879+
})
1880+
1881+
BeforeEach(func() {
1882+
s.Prepare(&mockRuntime{}, &mockPlugin{idx: "00", name: "test"})
1883+
})
1884+
1885+
It("should pass runtime version information to plugins", func() {
1886+
var (
1887+
runtimeName = "test-runtime"
1888+
runtimeVersion = "1.2.3"
1889+
)
1890+
1891+
s.runtime.name = runtimeName
1892+
s.runtime.version = runtimeVersion
1893+
1894+
s.Startup()
1895+
1896+
Expect(s.plugins[0].RuntimeName()).To(Equal(runtimeName))
1897+
Expect(s.plugins[0].RuntimeVersion()).To(Equal(runtimeVersion))
1898+
})
1899+
1900+
When("unchanged", func() {
1901+
It("should pass default timeout information to plugins", func() {
1902+
var (
1903+
registerTimeout = nri.DefaultPluginRegistrationTimeout
1904+
requestTimeout = nri.DefaultPluginRequestTimeout
1905+
)
1906+
1907+
s.Startup()
1908+
Expect(s.plugins[0].stub.RegistrationTimeout()).To(Equal(registerTimeout))
1909+
Expect(s.plugins[0].stub.RequestTimeout()).To(Equal(requestTimeout))
1910+
})
1911+
})
1912+
1913+
When("reconfigured", func() {
1914+
var (
1915+
registerTimeout = nri.DefaultPluginRegistrationTimeout + 5*time.Millisecond
1916+
requestTimeout = nri.DefaultPluginRequestTimeout + 7*time.Millisecond
1917+
)
1918+
1919+
BeforeEach(func() {
1920+
nri.SetPluginRegistrationTimeout(registerTimeout)
1921+
nri.SetPluginRequestTimeout(requestTimeout)
1922+
s.Prepare(&mockRuntime{}, &mockPlugin{idx: "00", name: "test"})
1923+
})
1924+
1925+
AfterEach(func() {
1926+
nri.SetPluginRegistrationTimeout(nri.DefaultPluginRegistrationTimeout)
1927+
nri.SetPluginRequestTimeout(nri.DefaultPluginRequestTimeout)
1928+
})
1929+
1930+
It("should pass configured timeout information to plugins", func() {
1931+
s.Startup()
1932+
Expect(s.plugins[0].stub.RegistrationTimeout()).To(Equal(registerTimeout))
1933+
Expect(s.plugins[0].stub.RequestTimeout()).To(Equal(requestTimeout))
1934+
})
1935+
})
1936+
})
1937+
18721938
// Notes:
18731939
//
18741940
// XXX FIXME KLUDGE

‎pkg/adaptation/suite_test.go

+28-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ func TestRuntime(t *testing.T) {
4343
}
4444

4545
const (
46-
startupTimeout = 2 * time.Second
46+
startupTimeout = 2 * time.Second
47+
defaultRuntimeName = "default-runtime-name"
48+
defaultRuntimeVersion = "0.1.2"
4749
)
4850

4951
// A test suite consist of a runtime and a set of plugins.
@@ -70,6 +72,13 @@ func (s *Suite) Prepare(runtime *mockRuntime, plugins ...*mockPlugin) string {
7072

7173
Expect(os.MkdirAll(etc, 0o755)).To(Succeed())
7274

75+
if runtime.name == "" {
76+
runtime.name = defaultRuntimeName
77+
}
78+
if runtime.version == "" {
79+
runtime.version = defaultRuntimeVersion
80+
}
81+
7382
s.dir = dir
7483
s.runtime = runtime
7584
s.plugins = plugins
@@ -126,6 +135,8 @@ func Log(format string, args ...interface{}) {
126135
}
127136

128137
type mockRuntime struct {
138+
name string
139+
version string
129140
options []nri.Option
130141
runtime *nri.Adaptation
131142
pods map[string]*api.PodSandbox
@@ -149,7 +160,7 @@ func (m *mockRuntime) Start(dir string) error {
149160
}
150161

151162
options = append(options, m.options...)
152-
m.runtime, err = nri.New("mockRuntime", "0.0.1", m.synchronize, m.update, options...)
163+
m.runtime, err = nri.New(m.name, m.version, m.synchronize, m.update, options...)
153164
if err != nil {
154165
return err
155166
}
@@ -323,6 +334,9 @@ type mockPlugin struct {
323334
stub stub.Stub
324335
mask stub.EventMask
325336

337+
runtime string
338+
version string
339+
326340
q *EventQ
327341
pods map[string]*api.PodSandbox
328342
ctrs map[string]*api.Container
@@ -477,6 +491,14 @@ func (m *mockPlugin) Stop() {
477491
m.q.Add(PluginStopped)
478492
}
479493

494+
func (m *mockPlugin) RuntimeName() string {
495+
return m.runtime
496+
}
497+
498+
func (m *mockPlugin) RuntimeVersion() string {
499+
return m.version
500+
}
501+
480502
func (m *mockPlugin) onClose() {
481503
if m.stub != nil {
482504
m.stub.Stop()
@@ -488,9 +510,12 @@ func (m *mockPlugin) onClose() {
488510
}
489511
}
490512

491-
func (m *mockPlugin) Configure(_ context.Context, _, _, _ string) (stub.EventMask, error) {
513+
func (m *mockPlugin) Configure(_ context.Context, _, runtime, version string) (stub.EventMask, error) {
492514
m.q.Add(PluginConfigured)
493515

516+
m.runtime = runtime
517+
m.version = version
518+
494519
return m.mask, nil
495520
}
496521

0 commit comments

Comments
 (0)
Please sign in to comment.