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

Unexpected behavior for WaitLog.WithOccurence #297

Closed
FlorianLehmann opened this issue Mar 20, 2021 · 2 comments
Closed

Unexpected behavior for WaitLog.WithOccurence #297

FlorianLehmann opened this issue Mar 20, 2021 · 2 comments

Comments

@FlorianLehmann
Copy link
Contributor

Describe the bug
When I define

NewLogStrategy("").
WithStartupTimeout(100 * time.Microsecond).
WithOccurrence(X)

for a container, it does not wait for X occurences. One occurence is enough to continue.

To Reproduce
func TestWaitShouldFailWithExactNumberOfOccurrences(t *testing.T) { target := noopStrategyTarget{ ioReaderCloser: ioutil.NopCloser(bytes.NewReader([]byte("hello\r\ndude"))), } wg := NewLogStrategy("dude"). WithStartupTimeout(100 * time.Microsecond). WithOccurrence(2) err := wg.WaitUntilReady(context.Background(), target) if err == nil { t.Fatal("expected error") } }

Expected behavior
it must wait for X occurences in the logs.

Additional context

currentOccurence := 0
LOOP:
for {
select {
case <-ctx.Done():
return ctx.Err()
default:
reader, err := target.Logs(ctx)
if err != nil {
time.Sleep(ws.PollInterval)
continue
}
b, err := ioutil.ReadAll(reader)
logs := string(b)
if strings.Contains(logs, ws.Log) {
currentOccurence++
if ws.Occurrence == 0 || currentOccurence >= ws.Occurrence-1 {
break LOOP
}

There is a variable currentOccurence defined before the loop. This variable is incremented in the loop each time the expected log appears. However, logs are read from the beginning. Therefore, the condition based on the number of occurences is always true if the expected log is present only once.

@mdelapenya
Copy link
Member

@FlorianLehmann should we close this issue? I see the PR was merged

Thanks!!

@FlorianLehmann
Copy link
Contributor Author

Yes, this has been resolved. It can be closed. Thanks

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

No branches or pull requests

2 participants