Skip to content

Commit

Permalink
Update unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
mismithhisler committed Dec 12, 2024
1 parent 0e787aa commit 70769af
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions manager/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -945,17 +945,9 @@ func TestRunner_Start(t *testing.T) {
t.Run("multi-template-no-render-cycle", func(t *testing.T) {
testConsul.SetKVString(t, "multi-template-no-cycle-foo", "bar")

out1, err := os.CreateTemp("", "")
if err != nil {
t.Fatal(err)
}
defer os.Remove(out1.Name())

out2, err := os.CreateTemp("", "")
if err != nil {
t.Fatal(err)
}
defer os.Remove(out2.Name())
tmpDir := t.TempDir()
out1 := filepath.Join(tmpDir, "out1")
out2 := filepath.Join(tmpDir, "out2")

minWait := 1 * time.Second
maxWait := 10 * time.Second
Expand All @@ -971,11 +963,11 @@ func TestRunner_Start(t *testing.T) {
Templates: &config.TemplateConfigs{
&config.TemplateConfig{
Contents: config.String(`{{ key "multi-template-no-cycle-foo" }}`),
Destination: config.String(out1.Name()),
Destination: config.String(out1),
},
&config.TemplateConfig{
Contents: config.String(`foobar`),
Destination: config.String(out2.Name()),
Destination: config.String(out2),
},
},
})
Expand All @@ -994,7 +986,7 @@ func TestRunner_Start(t *testing.T) {
case err := <-r.ErrCh:
t.Fatal(err)
case <-r.renderedCh:
act, err := os.ReadFile(out2.Name())
act, err := os.ReadFile(out2)
if err != nil {
t.Fatal(err)
}
Expand All @@ -1011,7 +1003,7 @@ func TestRunner_Start(t *testing.T) {
case err := <-r.ErrCh:
t.Fatal(err)
case <-r.renderedCh:
act, err := os.ReadFile(out1.Name())
act, err := os.ReadFile(out1)
if err != nil {
t.Fatal(err)
}
Expand All @@ -1026,19 +1018,21 @@ func TestRunner_Start(t *testing.T) {
// Update the value we are watching, it should update after the quiescence timer fires
testConsul.SetKVString(t, "multi-template-no-cycle-foo", "bar_again")

renderCount := 0
OUTER:
// Wait for the quiescence timer to fire and the value to actually render to disk
for {
select {
case err := <-r.ErrCh:
t.Fatal(err)
case <-r.renderedCh:
act, err := os.ReadFile(out1.Name())
if err != nil {
t.Fatal(err)
}
exp := "bar_again"
if exp != string(act) {
// Run() will be called a total of 3 times when the dep is updated.
// The first run will tick both the templates quiescence timers, and return
// early without sending a render event. The next 2 runs will be from both the
// templates quiescence timers firing. We don't want to move on until both of
// those take place.
renderCount++
if renderCount < 2 {
continue
}
break OUTER
Expand Down

0 comments on commit 70769af

Please sign in to comment.