| 12345678910111213141516171819202122232425262728293031323334 |
- package uhf
- import (
- "testing"
- "github.com/stretchr/testify/require"
- )
- func TestChannelEventsUseMonotonicIDs(t *testing.T) {
- channelEventMu.Lock()
- previousQueue := ChannelEventQueue
- previousNextID := channelEventNextID
- ChannelEventQueue = make([]ChannelEvent, 0, 50)
- channelEventNextID = 0
- channelEventMu.Unlock()
- t.Cleanup(func() {
- channelEventMu.Lock()
- ChannelEventQueue = previousQueue
- channelEventNextID = previousNextID
- channelEventMu.Unlock()
- })
- PushChannelEvent(ChannelEvent{RFIDTag: "A", Timestamp: 100})
- PushChannelEvent(ChannelEvent{RFIDTag: "B", Timestamp: 100})
- all := GetChannelEvents(0)
- require.Len(t, all, 2)
- require.Equal(t, uint64(1), all[0].ID)
- require.Equal(t, uint64(2), all[1].ID)
- afterFirst := GetChannelEvents(all[0].ID)
- require.Len(t, afterFirst, 1)
- require.Equal(t, "B", afterFirst[0].RFIDTag)
- }
|