Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions then/eventually.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,25 @@ func (t *RecordingTestingT) Failing() bool {
// Only used with Eventually
type Latest struct {
sync.Mutex
latestValue RecordingTestingT
latestValue *RecordingTestingT
}

// Get is used internally by Eventually to Get the last recorded test output from assertions passed into it
// Only used with Eventually
func (l *Latest) Get() RecordingTestingT {
func (l *Latest) Get() *RecordingTestingT {
l.Lock()
defer l.Unlock()
return l.latestValue
}

// Merge is used internally by Eventually to Merge the latest recorded test output from assertions passed into it with the last one
// Only used with Eventually
func (l *Latest) Merge(updated RecordingTestingT) RecordingTestingT {
func (l *Latest) Merge(updated *RecordingTestingT) *RecordingTestingT {
l.Lock()
defer l.Unlock()
if l.latestValue == nil {
return updated
}
var mergedFailures []FailureLog
for i, failure := range l.latestValue.failures {
if failure.failed {
Expand All @@ -101,7 +104,7 @@ func (l *Latest) Merge(updated RecordingTestingT) RecordingTestingT {
if l.latestValue.failures == nil {
mergedFailures = updated.failures
}
merged := RecordingTestingT{
merged := &RecordingTestingT{
failures: mergedFailures,
TestingT: l.latestValue.TestingT,
}
Expand All @@ -123,7 +126,7 @@ func (l *Latest) Merge(updated RecordingTestingT) RecordingTestingT {
func Eventually(t gocrest.TestingT, waitFor, tick time.Duration, assertions func(eventually gocrest.TestingT)) {

t.Helper()
channel := make(chan RecordingTestingT, 1)
channel := make(chan *RecordingTestingT, 1)
defer close(channel)

timer := time.NewTimer(waitFor)
Expand All @@ -137,7 +140,11 @@ func Eventually(t gocrest.TestingT, waitFor, tick time.Duration, assertions func
select {
case <-timer.C:
latestRecordingT := latestValue.Get()
t.Errorf(fmt.Sprintf("Eventually Failed after %s: \n", waitFor) + strings.Join(latestRecordingT.FailedTestOutputs(), "\n"))
var failedOutputs []string
if latestRecordingT != nil {
failedOutputs = latestRecordingT.FailedTestOutputs()
}
t.Errorf(fmt.Sprintf("Eventually Failed after %s: \n", waitFor) + strings.Join(failedOutputs, "\n"))
return
case <-tick:
tick = nil
Expand All @@ -147,7 +154,7 @@ func Eventually(t gocrest.TestingT, waitFor, tick time.Duration, assertions func
failures: []FailureLog{},
}
assertions(&recordedTesting)
channel <- recordedTesting
channel <- &recordedTesting
}()
case value := <-channel:
if !value.Failing() {
Expand Down
Loading