Skip to content

Commit

Permalink
[Juniper] Check type assertion and speed up unit test (#403)
Browse files Browse the repository at this point in the history
Check type assertion and speed up unit test
  • Loading branch information
alexmasi authored Jul 26, 2023
1 parent 635256a commit 4c246ee
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
11 changes: 8 additions & 3 deletions topo/node/juniper/juniper.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ var (
scrapliOperationTimeout = 300 * time.Second
// Wait for PKI cert infra
certGenTimeout = 10 * time.Minute
// Time between polls
certGenRetrySleep = 30 * time.Second
)

const (
Expand Down Expand Up @@ -129,14 +131,14 @@ func (n *Node) waitCertInfraReadyAndPushCert() error {
return resp.Failed
}
if strings.Contains(resp.Result, "error:") {
log.Infof("Cert infra isn't ready. Retrying in 30 sec. Response %s", multiresp.JoinedResult())
log.Infof("Cert infra isn't ready. Retrying in %v. Response %s", certGenRetrySleep, multiresp.JoinedResult())
}
if strings.Contains(resp.Result, "successfully") {
log.Infof("Cert Infra ready. Configured Certs. Response %s", multiresp.JoinedResult())
return nil
}
}
time.Sleep(30 * time.Second)
time.Sleep(certGenRetrySleep)
}

return fmt.Errorf("failed sending generate-self-signed commands")
Expand All @@ -160,7 +162,10 @@ func (n *Node) GenerateSelfSigned(ctx context.Context) error {
return err
}
for e := range w.ResultChan() {
p := e.Object.(*corev1.Pod)
p, ok := e.Object.(*corev1.Pod)
if !ok {
continue
}
if p.Status.Phase == corev1.PodRunning {
break
}
Expand Down
22 changes: 17 additions & 5 deletions topo/node/juniper/juniper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,19 @@ func TestGenerateSelfSigned(t *testing.T) {

reaction := func(action ktest.Action) (handled bool, ret watch.Interface, err error) {
f := &fakeWatch{
e: []watch.Event{{
Object: &corev1.Pod{
Status: corev1.PodStatus{
Phase: corev1.PodRunning,
e: []watch.Event{
{
// Test that watcher properly handles events with the wrong type.
Object: &corev1.ConfigMap{},
},
{
Object: &corev1.Pod{
Status: corev1.PodStatus{
Phase: corev1.PodRunning,
},
},
},
}},
},
}
return true, f, nil
}
Expand All @@ -124,6 +130,12 @@ func TestGenerateSelfSigned(t *testing.T) {
},
}

origCertGenRetrySleep := certGenRetrySleep
defer func() {
certGenRetrySleep = origCertGenRetrySleep
}()
certGenRetrySleep = time.Millisecond

tests := []struct {
desc string
wantErr bool
Expand Down

0 comments on commit 4c246ee

Please sign in to comment.