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

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

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