Change:
<!-- This form is for bug reports and feature requests ONLY! If you're looking for help check and the . --Is this a BUG REPORT or FEATURE REQUEST?: /kind bug What happened: For now, UT in doesn't work because callback function will never be called, is rewritten in this function : Another thing, i'm wondering why we rewrite device health in function which in this file: What you expected to happen: UT assertion should be executed. How to reproduce it (as minimally and precisely as possible): Add some logs in callback function of , it will show nothing. Anything else we need to know?: I will send a PR to fix this. /cc WDYT? /sig node
/assign
GitHub didn't allow me to assign the following users: RenaudWasTaken. Note that only can be assigned. <detailsIn response to : /assign Instructions for interacting with me using PR comments are available . If you have questions or suggestions related to my behavior, please file an issue against the repository. </details
Good catch

Discussion:
// Wait till grpc server is ready. for i := 0; i < 10; i++ { services := m.server.GetServiceInfo() <del> if len(services) > 1 { </del> <ins> if len(services) > 0 { </ins> break } time.Sleep(1 * time.Second)

// ListAndWatch lists devices and update that list according to the Update call func (m *Stub) ListAndWatch(e *pluginapi.Empty, s pluginapi.DevicePlugin_ListAndWatchServer) error { log.Println("ListAndWatch") <del> var devs []*pluginapi.Device for _, d := range m.devs { devs = append(devs, &pluginapi.Device{ ID:     d.ID, Health: pluginapi.Healthy, }) } s.Send(&pluginapi.ListAndWatchResponse{Devices: devs}) </del> <ins> s.Send(&pluginapi.ListAndWatchResponse{Devices: m.devs}) </ins> for { select {

import ( "path" "testing" <del> "time" </del> "github.com/stretchr/testify/require"

{ID: "AThirdDeviceId", Health: pluginapi.Healthy}, } <del> p, e := esetup(t, devs, socket, "mock", func(n string, a, u, r []pluginapi.Device) { require.Len(t, a, 1) require.Len(t, u, 1) require.Len(t, r, 1) require.Equal(t, a[0].ID, updated[1].ID) require.Equal(t, u[0].ID, updated[0].ID) require.Equal(t, u[0].Health, updated[0].Health) </del> <ins> callbackCount := 0 callbackChan := make(chan int) callback := func(n string, a, u, r []pluginapi.Device) { // Should be called twice: // one for plugin registration, one for plugin update. if callbackCount > 2 { t.FailNow() } // Check plugin registration if callbackCount == 0 { require.Len(t, a, 2) require.Len(t, u, 0) require.Len(t, r, 0) } // Check plugin update if callbackCount == 1 { require.Len(t, a, 1) require.Len(t, u, 1) require.Len(t, r, 1) require.Equal(t, a[0].ID, updated[1].ID) require.Equal(t, u[0].ID, updated[0].ID) require.Equal(t, u[0].Health, updated[0].Health) require.Equal(t, r[0].ID, devs[1].ID) } callbackCount++ callbackChan <- callbackCount } </ins> <del> require.Equal(t, r[0].ID, devs[1].ID) }) </del> <ins> p, e := esetup(t, devs, socket, "mock", callback) </ins> defer ecleanup(t, p, e) go e.run() <ins> // Wait for the first callback to be issued. <-callbackChan </ins> p.Update(updated) <del> time.Sleep(time.Second) </del> <ins> // Wait for the second callback to be issued. <-callbackChan </ins> e.mutex.Lock() defer e.mutex.Unlock()

err := p.Start() require.NoError(t, err) <del> e, err := newEndpointImpl(socket, "mock", make(map[string]pluginapi.Device), func(n string, a, u, r []pluginapi.Device) {}) </del> <ins> e, err := newEndpointImpl(socket, resourceName, make(map[string]pluginapi.Device), callback) </ins> require.NoError(t, err) return p, e