Этот коммит содержится в:
gedi 2016-06-13 23:47:24 +03:00
родитель f16addd9c9
коммит 2162380725

15
run.go
Просмотреть файл

@ -12,6 +12,7 @@ type runner struct {
sync.WaitGroup sync.WaitGroup
semaphore chan int semaphore chan int
stopOnFailure bool
features []*feature features []*feature
fmt Formatter // needs to support concurrency fmt Formatter // needs to support concurrency
initializer initializer initializer initializer
@ -22,8 +23,16 @@ func (r *runner) run() (failed bool) {
for _, ft := range r.features { for _, ft := range r.features {
go func(fail *bool, feat *feature) { go func(fail *bool, feat *feature) {
r.semaphore <- 1 r.semaphore <- 1
defer func() {
r.Done()
<-r.semaphore
}()
if r.stopOnFailure && *fail {
return
}
suite := &Suite{ suite := &Suite{
fmt: r.fmt, fmt: r.fmt,
stopOnFailure: r.stopOnFailure,
features: []*feature{feat}, features: []*feature{feat},
} }
r.initializer(suite) r.initializer(suite)
@ -31,8 +40,6 @@ func (r *runner) run() (failed bool) {
if suite.failed { if suite.failed {
*fail = true *fail = true
} }
<-r.semaphore
r.Done()
}(&failed, ft) }(&failed, ft)
} }
r.Wait() r.Wait()
@ -78,9 +85,6 @@ func Run(contextInitializer func(suite *Suite)) int {
if concurrency > 1 && format != "progress" { if concurrency > 1 && format != "progress" {
fatal(fmt.Errorf("when concurrency level is higher than 1, only progress format is supported")) fatal(fmt.Errorf("when concurrency level is higher than 1, only progress format is supported"))
} }
if concurrency > 1 && sof {
fatal(fmt.Errorf("when concurrency level is higher than 1, cannot stop on first failure for now"))
}
formatter, err := findFmt(format) formatter, err := findFmt(format)
fatal(err) fatal(err)
@ -92,6 +96,7 @@ func Run(contextInitializer func(suite *Suite)) int {
initializer: contextInitializer, initializer: contextInitializer,
semaphore: make(chan int, concurrency), semaphore: make(chan int, concurrency),
features: features, features: features,
stopOnFailure: sof,
} }
if failed := r.run(); failed { if failed := r.run(); failed {