Skip to content

Commit 92165d8

Browse files
authored
[NPM] Fix recent unit test failures from each controller (#880)
* Use sharedInformer for only local storage to cache resource to make deterministic unit tests * add comments in the codes * add comments for future enhancement for unit tests
1 parent 8c661d2 commit 92165d8

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

npm/nameSpaceController_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ func (f *nameSpaceFixture) newNsController(stopCh chan struct{}) {
7070
for _, ns := range f.nsLister {
7171
f.kubeInformer.Core().V1().Namespaces().Informer().GetIndexer().Add(ns)
7272
}
73-
74-
f.kubeInformer.Start(stopCh)
73+
// Do not start informer to avoid unnecessary event triggers.
74+
// (TODO) Leave stopCh and below commented code to enhance UTs to even check event triggers as well later if possible
75+
//f.kubeInformer.Start()
7576
}
7677

7778
func (f *nameSpaceFixture) ipSetSave(ipsetConfigFile string) {

npm/networkPolicyController_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ func (f *netPolFixture) newNetPolController(stopCh chan struct{}) {
7878
f.kubeInformer.Networking().V1().NetworkPolicies().Informer().GetIndexer().Add(netPol)
7979
}
8080

81-
f.kubeInformer.Start(stopCh)
81+
// Do not start informer to avoid unnecessary event triggers
82+
// (TODO): Leave stopCh and below commented code to enhance UTs to even check event triggers as well later if possible
83+
//f.kubeInformer.Start(stopCh)
8284
}
8385

8486
func (f *netPolFixture) saveIpTables(iptablesConfigFile string) {

npm/podController_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ func (f *podFixture) newPodController(stopCh chan struct{}) {
6767
f.kubeInformer.Core().V1().Pods().Informer().GetIndexer().Add(pod)
6868
}
6969

70-
f.kubeInformer.Start(stopCh)
70+
// Do not start informer to avoid unnecessary event triggers
71+
// (TODO): Leave stopCh and below commented code to enhance UTs to even check event triggers as well later if possible
72+
//f.kubeInformer.Start(stopCh)
7173
}
7274

7375
func (f *podFixture) ipSetSave(ipsetConfigFile string) {

0 commit comments

Comments
 (0)