Skip to content

Commit e462d7b

Browse files
Rahul Sharmarahulait
authored andcommitted
add unittest to test processing older node requests
1 parent 1912d41 commit e462d7b

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

cloud/linode/node_controller.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,9 @@ func (s *nodeController) Run(stopCh <-chan struct{}) {
103103
func (s *nodeController) addNodeToQueue(node *v1.Node) {
104104
s.Lock()
105105
defer s.Unlock()
106-
s.nodeLastAdded[node.Name] = time.Now()
107-
s.queue.Add(nodeRequest{node: node, timestamp: time.Now()})
106+
currTime := time.Now()
107+
s.nodeLastAdded[node.Name] = currTime
108+
s.queue.Add(nodeRequest{node: node, timestamp: currTime})
108109
}
109110

110111
// worker runs a worker thread that dequeues new or modified nodes and processes

cloud/linode/node_controller_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ func TestNodeController_processNext(t *testing.T) {
100100
}
101101
})
102102

103+
t.Run("should return no error if timestamp for node being processed is older than the most recent request", func(t *testing.T) {
104+
controller.addNodeToQueue(node)
105+
controller.nodeLastAdded["test"] = time.Now().Add(controller.ttl)
106+
result := controller.processNext()
107+
assert.True(t, result, "processNext should return true")
108+
if queue.Len() != 0 {
109+
t.Errorf("expected queue to be empty, got %d items", queue.Len())
110+
}
111+
})
112+
103113
t.Run("should return no error if node exists", func(t *testing.T) {
104114
controller.addNodeToQueue(node)
105115
publicIP := net.ParseIP("172.234.31.123")

0 commit comments

Comments
 (0)