Skip to content

Commit 37b9262

Browse files
committed
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 8cfc175 commit 37b9262

File tree

2 files changed

+99
-3
lines changed

2 files changed

+99
-3
lines changed

pkg/adaptation/adaptation_suite_test.go

Lines changed: 66 additions & 0 deletions
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

Lines changed: 33 additions & 3 deletions
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
@@ -107,6 +116,11 @@ func (s *Suite) WaitForPluginsToSync() {
107116
for _, plugin := range s.plugins {
108117
Expect(plugin.Wait(PluginSynchronized, timeout)).To(Succeed())
109118
}
119+
120+
// TODO(klihub): We lack the means to wait for synchronized plugins
121+
// to get fully registered by mockRuntime. However, the tests still
122+
// expect WaitForPluginsToSync to do that...
123+
time.Sleep(25 * time.Millisecond)
110124
}
111125

112126
// Cleanup the test suite.
@@ -126,6 +140,8 @@ func Log(format string, args ...interface{}) {
126140
}
127141

128142
type mockRuntime struct {
143+
name string
144+
version string
129145
options []nri.Option
130146
runtime *nri.Adaptation
131147
pods map[string]*api.PodSandbox
@@ -149,7 +165,7 @@ func (m *mockRuntime) Start(dir string) error {
149165
}
150166

151167
options = append(options, m.options...)
152-
m.runtime, err = nri.New("mockRuntime", "0.0.1", m.synchronize, m.update, options...)
168+
m.runtime, err = nri.New(m.name, m.version, m.synchronize, m.update, options...)
153169
if err != nil {
154170
return err
155171
}
@@ -305,6 +321,9 @@ type mockPlugin struct {
305321
stub stub.Stub
306322
mask stub.EventMask
307323

324+
runtime string
325+
version string
326+
308327
q *EventQ
309328
pods map[string]*api.PodSandbox
310329
ctrs map[string]*api.Container
@@ -459,6 +478,14 @@ func (m *mockPlugin) Stop() {
459478
m.q.Add(PluginStopped)
460479
}
461480

481+
func (m *mockPlugin) RuntimeName() string {
482+
return m.runtime
483+
}
484+
485+
func (m *mockPlugin) RuntimeVersion() string {
486+
return m.version
487+
}
488+
462489
func (m *mockPlugin) onClose() {
463490
if m.stub != nil {
464491
m.stub.Stop()
@@ -470,9 +497,12 @@ func (m *mockPlugin) onClose() {
470497
}
471498
}
472499

473-
func (m *mockPlugin) Configure(_ context.Context, _, _, _ string) (stub.EventMask, error) {
500+
func (m *mockPlugin) Configure(_ context.Context, _, runtime, version string) (stub.EventMask, error) {
474501
m.q.Add(PluginConfigured)
475502

503+
m.runtime = runtime
504+
m.version = version
505+
476506
return m.mask, nil
477507
}
478508

0 commit comments

Comments
 (0)