mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Add a simple endpoint test for GetPreferredAllocation()
More extensive tests that exercise the allocation logic are to follow.
This commit is contained in:
parent
cbd405d85c
commit
bb08fd1135
@ -159,6 +159,40 @@ func TestAllocate(t *testing.T) {
|
|||||||
require.Equal(t, resp, respOut)
|
require.Equal(t, resp, respOut)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetPreferredAllocation(t *testing.T) {
|
||||||
|
socket := path.Join("/tmp", esocketName)
|
||||||
|
callbackCount := 0
|
||||||
|
callbackChan := make(chan int)
|
||||||
|
p, e := esetup(t, []*pluginapi.Device{}, socket, "mock", func(n string, d []pluginapi.Device) {
|
||||||
|
callbackCount++
|
||||||
|
callbackChan <- callbackCount
|
||||||
|
})
|
||||||
|
defer ecleanup(t, p, e)
|
||||||
|
|
||||||
|
resp := &pluginapi.PreferredAllocationResponse{
|
||||||
|
ContainerResponses: []*pluginapi.ContainerPreferredAllocationResponse{
|
||||||
|
{DeviceIDs: []string{"device0", "device1", "device2"}},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
p.SetGetPreferredAllocFunc(func(r *pluginapi.PreferredAllocationRequest, devs map[string]pluginapi.Device) (*pluginapi.PreferredAllocationResponse, error) {
|
||||||
|
return resp, nil
|
||||||
|
})
|
||||||
|
|
||||||
|
go e.run()
|
||||||
|
// Wait for the callback to be issued.
|
||||||
|
select {
|
||||||
|
case <-callbackChan:
|
||||||
|
break
|
||||||
|
case <-time.After(time.Second):
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
|
||||||
|
respOut, err := e.getPreferredAllocation([]string{}, []string{}, -1)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, resp, respOut)
|
||||||
|
}
|
||||||
|
|
||||||
func esetup(t *testing.T, devs []*pluginapi.Device, socket, resourceName string, callback monitorCallback) (*Stub, *endpointImpl) {
|
func esetup(t *testing.T, devs []*pluginapi.Device, socket, resourceName string, callback monitorCallback) (*Stub, *endpointImpl) {
|
||||||
p := NewDevicePluginStub(devs, socket, resourceName, false, false)
|
p := NewDevicePluginStub(devs, socket, resourceName, false, false)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user