Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added occurrence for the WaitLogStrategy #100

Merged
merged 1 commit into from
Oct 3, 2019

Conversation

gianarb
Copy link
Collaborator

@gianarb gianarb commented Oct 2, 2019

This is related to the work @giorgioazzinnaro is doing here
#98 .

Now you can declare how many times a log line should appear before
having the container declared as ready.

Signed-off-by: Gianluca Arbezzano gianarb92@gmail.com

@gianarb
Copy link
Collaborator Author

gianarb commented Oct 2, 2019

/cc @giorgioazzinnaro @mdelapenya can you have a look?

Copy link
Member

@mdelapenya mdelapenya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It LGTM, although I added a few cosmetic, minor comments

wait/log.go Outdated
@@ -18,6 +18,7 @@ type LogStrategy struct {
// additional properties
Log string
PollInterval time.Duration
Occurence int
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-	Occurence    int
+	Occurrence    int

wait/log.go Outdated
@@ -26,6 +27,7 @@ func NewLogStrategy(log string) *LogStrategy {
startupTimeout: defaultStartupTimeout(),
Log: log,
PollInterval: 100 * time.Millisecond,
Occurence: 1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

wait/log.go Outdated
@@ -46,6 +48,15 @@ func (ws *LogStrategy) WithPollInterval(pollInterval time.Duration) *LogStrategy
return ws
}

func (ws *LogStrategy) WithOccurence(o int) *LogStrategy {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@@ -61,6 +72,7 @@ func (ws *LogStrategy) WaitUntilReady(ctx context.Context, target StrategyTarget
// limit context to startupTimeout
ctx, cancelContext := context.WithTimeout(ctx, ws.startupTimeout)
defer cancelContext()
currentOccurence := 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-	currentOccurence := 0
+	currentOccurrence := 0

@@ -77,7 +89,10 @@ LOOP:
b, err := ioutil.ReadAll(reader)
logs := string(b)
if strings.Contains(logs, ws.Log) {
break LOOP
currentOccurence++
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

wait/log_test.go Outdated
}
wg := NewLogStrategy("dude").
WithStartupTimeout(100 * time.Microsecond).
WithOccurence(2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

wait/log_test.go Outdated
}
}

func TestWaitWithMaxOccurenceButItWillNeverHappen(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

wait/log_test.go Outdated
}
wg := NewLogStrategy("blaaa").
WithStartupTimeout(100 * time.Microsecond).
WithOccurence(2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add an example with a high number of occurrences (around a hundred)? This way we will exercise the infinite loop better than with just two loops

@gianarb gianarb force-pushed the feature/wait-log-occurnace branch 2 times, most recently from 456f324 to f04588c Compare October 3, 2019 21:40
This is related to the work @giorgioazzinnaro is doing here
#98 .

Now you can declare how many times a log line should appear before
having the container declared as ready.

Signed-off-by: Gianluca Arbezzano <gianarb92@gmail.com>
@gianarb gianarb merged commit 5a28565 into master Oct 3, 2019
@gianarb gianarb deleted the feature/wait-log-occurnace branch October 3, 2019 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants