Skip to content

Commit

Permalink
Updated so that we run all tests concurrent now
Browse files Browse the repository at this point in the history
  • Loading branch information
lonnblad committed Mar 26, 2020
1 parent 4da503a commit edfd2a1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 55 deletions.
26 changes: 17 additions & 9 deletions fmt_progress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ func FeatureContext(s *godog.Suite) {
`

require.True(t, r.run())
failed := r.concurrent(1, func() Formatter { return progressFunc("progress", w) })
require.True(t, failed)

actual := buf.String()
assert.Equal(t, expected, actual)
Expand All @@ -107,10 +108,11 @@ func TestProgressFormatterWhenStepPanics(t *testing.T) {
},
}

require.True(t, r.run())
failed := r.concurrent(1, func() Formatter { return progressFunc("progress", w) })
require.True(t, failed)

actual := buf.String()
assert.Contains(t, actual, "godog/fmt_progress_test.go:106")
assert.Contains(t, actual, "godog/fmt_progress_test.go:107")
}

func TestProgressFormatterWithPassingMultisteps(t *testing.T) {
Expand All @@ -135,7 +137,8 @@ func TestProgressFormatterWithPassingMultisteps(t *testing.T) {
},
}

assert.False(t, r.run())
failed := r.concurrent(1, func() Formatter { return progressFunc("progress", w) })
require.False(t, failed)
}

func TestProgressFormatterWithFailingMultisteps(t *testing.T) {
Expand All @@ -160,7 +163,8 @@ func TestProgressFormatterWithFailingMultisteps(t *testing.T) {
},
}

require.True(t, r.run())
failed := r.concurrent(1, func() Formatter { return progressFunc("progress", w) })
require.True(t, failed)

expected := `.F 2
Expand Down Expand Up @@ -202,7 +206,8 @@ func TestProgressFormatterWithPanicInMultistep(t *testing.T) {
},
}

assert.True(t, r.run())
failed := r.concurrent(1, func() Formatter { return progressFunc("progress", w) })
require.True(t, failed)
}

func TestProgressFormatterMultistepTemplates(t *testing.T) {
Expand All @@ -226,7 +231,8 @@ func TestProgressFormatterMultistepTemplates(t *testing.T) {
},
}

require.False(t, r.run())
failed := r.concurrent(1, func() Formatter { return progressFunc("progress", w) })
require.False(t, failed)

expected := `.U 2
Expand Down Expand Up @@ -291,7 +297,8 @@ Feature: basic
},
}

assert.False(t, r.run())
failed := r.concurrent(1, func() Formatter { return progressFunc("progress", w) })
require.False(t, failed)
}

func TestProgressFormatterWhenMultiStepHasStepWithArgument(t *testing.T) {
Expand Down Expand Up @@ -326,7 +333,8 @@ Feature: basic
},
}

require.True(t, r.run())
failed := r.concurrent(1, func() Formatter { return progressFunc("progress", w) })
require.True(t, failed)

expected := `.F 2
Expand Down
45 changes: 4 additions & 41 deletions run.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,23 +110,6 @@ func (r *runner) concurrent(rate int, formatterFn func() Formatter) (failed bool
return
}

func (r *runner) run() bool {
suite := &Suite{
fmt: r.fmt,
randomSeed: r.randomSeed,
stopOnFailure: r.stopOnFailure,
strict: r.strict,
features: r.features,
}
r.initializer(suite)

r.fmt.TestRunStarted()
suite.run()
r.fmt.Summary()

return suite.failed
}

// RunWithOptions is same as Run function, except
// it uses Options provided in order to run the
// test suite without parsing flags
Expand Down Expand Up @@ -169,10 +152,10 @@ func RunWithOptions(suite string, contextInitializer func(suite *Suite), opt Opt
}
}

if opt.Concurrency > 1 && !supportsConcurrency(opt.Format) {
fmt.Fprintln(os.Stderr, fmt.Errorf("format \"%s\" does not support concurrent execution", opt.Format))
return exitOptionError
if opt.Concurrency < 1 {
opt.Concurrency = 1
}

formatter := FindFmt(opt.Format)
if nil == formatter {
var names []string
Expand Down Expand Up @@ -214,12 +197,7 @@ func RunWithOptions(suite string, contextInitializer func(suite *Suite), opt Opt
_, filename, _, _ := runtime.Caller(1)
os.Setenv("GODOG_TESTED_PACKAGE", runsFromPackage(filename))

var failed bool
if opt.Concurrency > 1 {
failed = r.concurrent(opt.Concurrency, func() Formatter { return formatter(suite, output) })
} else {
failed = r.run()
}
failed := r.concurrent(opt.Concurrency, func() Formatter { return formatter(suite, output) })

// @TODO: should prevent from having these
os.Setenv("GODOG_SEED", "")
Expand Down Expand Up @@ -275,18 +253,3 @@ func Run(suite string, contextInitializer func(suite *Suite)) int {

return RunWithOptions(suite, contextInitializer, opt)
}

func supportsConcurrency(format string) bool {
switch format {
case "progress", "junit":
return true
case "events":
return true
case "cucumber":
return true
case "pretty":
return true
default:
return true // enables concurrent custom formatters to work
}
}
15 changes: 10 additions & 5 deletions run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ func TestFailsOrPassesBasedOnStrictModeWhenHasPendingSteps(t *testing.T) {
},
}

assert.False(t, r.run())
failed := r.concurrent(1, func() Formatter { return progressFunc("progress", ioutil.Discard) })
require.False(t, failed)

r.strict = true
assert.True(t, r.run())
failed = r.concurrent(1, func() Formatter { return progressFunc("progress", ioutil.Discard) })
require.True(t, failed)
}

func TestFailsOrPassesBasedOnStrictModeWhenHasUndefinedSteps(t *testing.T) {
Expand All @@ -98,10 +100,12 @@ func TestFailsOrPassesBasedOnStrictModeWhenHasUndefinedSteps(t *testing.T) {
},
}

assert.False(t, r.run())
failed := r.concurrent(1, func() Formatter { return progressFunc("progress", ioutil.Discard) })
require.False(t, failed)

r.strict = true
assert.True(t, r.run())
failed = r.concurrent(1, func() Formatter { return progressFunc("progress", ioutil.Discard) })
require.True(t, failed)
}

func TestShouldFailOnError(t *testing.T) {
Expand All @@ -121,7 +125,8 @@ func TestShouldFailOnError(t *testing.T) {
},
}

assert.True(t, r.run())
failed := r.concurrent(1, func() Formatter { return progressFunc("progress", ioutil.Discard) })
require.True(t, failed)
}

func TestFailsWithUnknownFormatterOptionError(t *testing.T) {
Expand Down

0 comments on commit edfd2a1

Please sign in to comment.