mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Merge pull request #58941 from vikaschoudhary16/test-allocate
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Add unit test for endpoint allocate **What this PR does / why we need it**: Adds a unit test for covering `allocate` function at endpoint. **Release note**: ```release-note None ``` /kind testing /area hw-accelerators /cc @jiayingz @vishh @derekwaynecarr @RenaudWasTaken @resouer @ConnorDoyle
This commit is contained in:
commit
056e9ecc43
@ -19,6 +19,7 @@ package devicemanager
|
|||||||
import (
|
import (
|
||||||
"path"
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
@ -111,6 +112,56 @@ func TestRun(t *testing.T) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAllocate(t *testing.T) {
|
||||||
|
socket := path.Join("/tmp", esocketName)
|
||||||
|
devs := []*pluginapi.Device{
|
||||||
|
{ID: "ADeviceId", Health: pluginapi.Healthy},
|
||||||
|
}
|
||||||
|
callbackCount := 0
|
||||||
|
callbackChan := make(chan int)
|
||||||
|
p, e := esetup(t, devs, socket, "mock", func(n string, a, u, r []pluginapi.Device) {
|
||||||
|
callbackCount++
|
||||||
|
callbackChan <- callbackCount
|
||||||
|
})
|
||||||
|
defer ecleanup(t, p, e)
|
||||||
|
|
||||||
|
resp := new(pluginapi.AllocateResponse)
|
||||||
|
resp.Devices = append(resp.Devices, &pluginapi.DeviceSpec{
|
||||||
|
ContainerPath: "/dev/aaa",
|
||||||
|
HostPath: "/dev/aaa",
|
||||||
|
Permissions: "mrw",
|
||||||
|
})
|
||||||
|
|
||||||
|
resp.Devices = append(resp.Devices, &pluginapi.DeviceSpec{
|
||||||
|
ContainerPath: "/dev/bbb",
|
||||||
|
HostPath: "/dev/bbb",
|
||||||
|
Permissions: "mrw",
|
||||||
|
})
|
||||||
|
|
||||||
|
resp.Mounts = append(resp.Mounts, &pluginapi.Mount{
|
||||||
|
ContainerPath: "/container_dir1/file1",
|
||||||
|
HostPath: "host_dir1/file1",
|
||||||
|
ReadOnly: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
p.SetAllocFunc(func(r *pluginapi.AllocateRequest, devs map[string]pluginapi.Device) (*pluginapi.AllocateResponse, 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.allocate([]string{"ADeviceId"})
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, resp, respOut)
|
||||||
|
}
|
||||||
|
|
||||||
func TestGetDevices(t *testing.T) {
|
func TestGetDevices(t *testing.T) {
|
||||||
e := endpointImpl{
|
e := endpointImpl{
|
||||||
devices: map[string]pluginapi.Device{
|
devices: map[string]pluginapi.Device{
|
||||||
|
Loading…
Reference in New Issue
Block a user