(t *testing.T)
| 93 | } |
| 94 | |
| 95 | func TestPluginManager(t *testing.T) { |
| 96 | ctrl := gomock.NewController(t) |
| 97 | fnp := NewMockNetworkPlugin(ctrl) |
| 98 | defer fnp.Finish() |
| 99 | pm := network.NewPluginManager(fnp) |
| 100 | |
| 101 | fnp.EXPECT().Name().Return("someNetworkPlugin").AnyTimes() |
| 102 | |
| 103 | allCreatedWg := sync.WaitGroup{} |
| 104 | allCreatedWg.Add(1) |
| 105 | allDoneWg := sync.WaitGroup{} |
| 106 | |
| 107 | // 10 pods, 4 setup/status/teardown runs each. Ensure that network locking |
| 108 | // works and the pod map isn't concurrently accessed |
| 109 | for i := 0; i < 10; i++ { |
| 110 | podName := fmt.Sprintf("pod%d", i) |
| 111 | containerID := config.ContainerID{ID: podName} |
| 112 | |
| 113 | fnp.EXPECT().SetUpPod("", podName, containerID).Return(nil).Times(4) |
| 114 | fnp.EXPECT().GetPodNetworkStatus( |
| 115 | "", |
| 116 | podName, |
| 117 | containerID, |
| 118 | ).Return( |
| 119 | &network.PodNetworkStatus{IP: net.ParseIP("1.2.3.4")}, |
| 120 | nil, |
| 121 | ).Times( |
| 122 | 4, |
| 123 | ) |
| 124 | fnp.EXPECT().TearDownPod("", podName, containerID).Return(nil).Times(4) |
| 125 | |
| 126 | for x := 0; x < 4; x++ { |
| 127 | allDoneWg.Add(1) |
| 128 | go func(name string, id config.ContainerID, num int) { |
| 129 | defer allDoneWg.Done() |
| 130 | |
| 131 | // Block all goroutines from running until all have |
| 132 | // been created and are ready. This ensures we |
| 133 | // have more pod network operations running |
| 134 | // concurrently. |
| 135 | allCreatedWg.Wait() |
| 136 | |
| 137 | if err := pm.SetUpPod("", name, id, nil, nil); err != nil { |
| 138 | t.Errorf("Failed to set up pod %q: %v", name, err) |
| 139 | return |
| 140 | } |
| 141 | |
| 142 | if _, err := pm.GetPodNetworkStatus("", name, id); err != nil { |
| 143 | t.Errorf("Failed to inspect pod %q: %v", name, err) |
| 144 | return |
| 145 | } |
| 146 | |
| 147 | if err := pm.TearDownPod("", name, id); err != nil { |
| 148 | t.Errorf("Failed to tear down pod %q: %v", name, err) |
| 149 | return |
| 150 | } |
| 151 | }(podName, containerID, x) |
| 152 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…