Skip to content

EventuallyWithT does not always copy the last errors #1437

@cszczepaniak

Description

@cszczepaniak

The documentation for EventuallyWithT states:

// If the condition is not met before waitFor, the collected errors of
// the last tick are copied to t.

However, it is possible to show that this is not the case with the following test:

func TestEventuallyWithTFalse(t *testing.T) {
	mockT := new(CollectT)

	var calledOnce bool
	condition := func(collect *CollectT) {
		if calledOnce {
			time.Sleep(time.Second)
		}
		True(collect, false)
		calledOnce = true
	}

	False(t, EventuallyWithT(mockT, condition, 100*time.Millisecond, 20*time.Millisecond))
	Len(t, mockT.errors, 2)
}

This test fails because the errors do not get copied; there is a race condition condition between the condition-checking goroutine and the assertion's goroutine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions