Skip to content

Commit 07b200d

Browse files
committed
hide more methods drive more coverage
1 parent d0029fb commit 07b200d

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

cns/restserver/internalapi_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ func TestCreateAndUpdateNCWithSecondaryIPNCVersion(t *testing.T) {
304304
}
305305
}
306306

307-
func TestSyncHostNCVersion(t *testing.T) {
307+
func TestStartSyncHostNCVersionLoop(t *testing.T) {
308308
// cns.KubernetesCRD has one more logic compared to other orchestrator type, so test both of them
309309
orchestratorTypes := []string{cns.Kubernetes, cns.KubernetesCRD}
310310
for _, orchestratorType := range orchestratorTypes {
@@ -349,7 +349,12 @@ func TestSyncHostNCVersion(t *testing.T) {
349349
defer cleanupIMDS()
350350

351351
// When syncing the host NC version, it will use the orchestratorType passed in.
352-
svc.SyncHostNCVersion(context.Background(), orchestratorType)
352+
cnsconf := configuration.CNSConfig{
353+
SyncHostNCVersionIntervalMs: 100,
354+
ChannelMode: orchestratorType,
355+
}
356+
svc.StartSyncHostNCVersionLoop(t.Context(), cnsconf)
357+
svc.ncSyncState.Wait(t.Context()) // wait for at leat one run
353358
containerStatus = svc.state.ContainerStatus[req.NetworkContainerid]
354359
if containerStatus.HostVersion != "0" {
355360
t.Errorf("Unexpected containerStatus.HostVersion %s, expected host version should be 0 in string", containerStatus.HostVersion)
@@ -400,7 +405,8 @@ func TestPendingIPsGotUpdatedWhenSyncHostNCVersion(t *testing.T) {
400405
cleanup := setMockNMAgent(svc, mnma)
401406
defer cleanup()
402407

403-
svc.SyncHostNCVersion(context.Background(), cns.CRD)
408+
svc.StartSyncHostNCVersionLoop(t.Context(), fastcnsconf)
409+
svc.ncSyncState.Wait(t.Context()) // wait for at leat one run
404410
containerStatus = svc.state.ContainerStatus[req.NetworkContainerid]
405411

406412
receivedSecondaryIPConfigs = containerStatus.CreateNetworkContainerRequest.SecondaryIPConfigs

cns/restserver/synchostnc.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ func (service *HTTPRestService) StartSyncHostNCVersionLoop(ctx context.Context,
7171
timeout := time.Duration(cnsconfig.SyncHostNCVersionIntervalMs) * time.Millisecond
7272
for {
7373
timedCtx, cancel := context.WithTimeout(ctx, timeout)
74-
if service.SyncHostNCVersion(timedCtx, cnsconfig.ChannelMode) {
74+
if service.syncHostNCVersionWrapper(timedCtx, cnsconfig.ChannelMode) {
7575
one.Do(service.ncSyncState.NotifyReady)
7676
}
7777
cancel()
7878
select {
7979
case <-ticker.C:
8080
timedCtx, cancel := context.WithTimeout(ctx, timeout)
81-
if service.SyncHostNCVersion(timedCtx, cnsconfig.ChannelMode) {
81+
if service.syncHostNCVersionWrapper(timedCtx, cnsconfig.ChannelMode) {
8282
one.Do(service.ncSyncState.NotifyReady)
8383
}
8484
cancel()
@@ -95,7 +95,7 @@ func (service *HTTPRestService) StartSyncHostNCVersionLoop(ctx context.Context,
9595
// SyncHostNCVersion will check NC version from NMAgent and save it as host NC version in container status.
9696
// If NMAgent NC version got updated, CNS will refresh the pending programming IP status.
9797
// returns true if soemthing was progammeed
98-
func (service *HTTPRestService) SyncHostNCVersion(ctx context.Context, channelMode string) bool {
98+
func (service *HTTPRestService) syncHostNCVersionWrapper(ctx context.Context, channelMode string) bool {
9999
service.Lock()
100100
defer service.Unlock()
101101
start := time.Now()

0 commit comments

Comments
 (0)