Skip to content

Commit

Permalink
Consolidate and simplify ruby-specific logic
Browse files Browse the repository at this point in the history
Drop emitter package in favor of moving more logic
into run and runner packages.
  • Loading branch information
ajbouh committed Jul 24, 2016
1 parent 0a5ab7b commit 7425d57
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 80 deletions.
9 changes: 7 additions & 2 deletions src/qa/cmd/run/execution-flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ import (
"strings"

"qa/cmd"
"qa/emitter"
"qa/runner"
"qa/runner/server"
)

var defaultGlobs = map[string]string{
"rspec": "spec/**/*spec.rb",
"minitest": "test/**/test*.rb",
"test-unit": "test/**/test*.rb",
}

type executionFlags struct {
jobs *int
squashPolicy *runner.SquashPolicy
Expand Down Expand Up @@ -101,7 +106,7 @@ func (f *executionFlags) RunnerConfigs(env *cmd.Env, runnerSpecs []string) []run
runnerName := runnerSpecSplit[0]
var lister runner.FileLister
if len(runnerSpecSplit) == 1 {
lister = runner.NewFileGlob(env.Dir, []string{emitter.DefaultGlob(runnerName)})
lister = runner.NewFileGlob(env.Dir, []string{defaultGlobs[runnerName]})
} else {
lister = runner.NewFileGlob(env.Dir, runnerSpecSplit[1:])
}
Expand Down
45 changes: 41 additions & 4 deletions src/qa/cmd/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"syscall"

"qa/cmd"
"qa/emitter"
"qa/runner"
"qa/runner/ruby"
"qa/runner/server"
"qa/suite"
"qa/tapjio"
Expand All @@ -24,19 +24,56 @@ type Env struct {
Server *server.Server
}

type contextStarter func(
srv *server.Server,
workerEnvs []map[string]string,
runnerConfig runner.Config) (runner.Context, error)

func rubyContextStarter(runnerAssetName string) contextStarter {
return func(
srv *server.Server,
workerEnvs []map[string]string,
runnerConfig runner.Config) (runner.Context, error) {

config := &ruby.ContextConfig{
RunnerConfig: runnerConfig,
Rubylib: []string{"spec", "lib", "test"},
RunnerAssetName: runnerAssetName,
}

ctx, err := ruby.StartContext(srv, workerEnvs, config)
if err != nil {
return nil, err
}

return ctx, nil
}
}

var starters = map[string]contextStarter{
"rspec": rubyContextStarter("ruby/rspec.rb"),
"minitest": rubyContextStarter("ruby/minitest.rb"),
"test-unit": rubyContextStarter("ruby/test-unit.rb"),
}

func Run(env *Env) (tapjio.FinalEvent, error) {
var final tapjio.FinalEvent

var testRunners []runner.TestRunner
for _, runnerConfig := range env.RunnerConfigs {
em, err := emitter.Resolve(env.Server, env.WorkerEnvs, runnerConfig)
defer em.Close()
starter, ok := starters[runnerConfig.Name]
if !ok {
return final, errors.New("Could not find starter: " + runnerConfig.Name)
}

ctx, err := starter(env.Server, env.WorkerEnvs, runnerConfig)
defer ctx.Close()
if err != nil {
fmt.Fprintf(os.Stderr, "Error! %v\n", err)
return final, err
}

traceEvents, runners, err := em.EnumerateTests()
traceEvents, runners, err := ctx.EnumerateRunners()
if err != nil {
return final, err
}
Expand Down
68 changes: 0 additions & 68 deletions src/qa/emitter/emitter.go

This file was deleted.

15 changes: 9 additions & 6 deletions src/qa/runner/ruby/ruby.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type context struct {
config *ContextConfig
}

func StartContext(cfg *ContextConfig, server *server.Server, workerEnvs []map[string]string) (*context, error) {
func StartContext(server *server.Server, workerEnvs []map[string]string, cfg *ContextConfig) (*context, error) {
requestCh := make(chan interface{}, 1)

runnerCfg := cfg.RunnerConfig
Expand Down Expand Up @@ -90,6 +90,9 @@ func StartContext(cfg *ContextConfig, server *server.Server, workerEnvs []map[st
if err != nil {
return nil, err
}
go func() {
cmd.Process.Wait()
}()

return &context{
requestCh: requestCh,
Expand All @@ -100,20 +103,20 @@ func StartContext(cfg *ContextConfig, server *server.Server, workerEnvs []map[st
}

// TODO(adamb) Should also cancel all existing waitgroups
func (self *context) Close() (err error) {
func (self *context) Close() error {
close(self.requestCh)

if self.process != nil {
err = self.process.Kill()
err := self.process.Kill()
if err != nil {
_, err = self.process.Wait()
return err
}
}

return
return nil
}

func (self *context) EnumerateTests() (traceEvents []tapjio.TraceEvent, testRunners []runner.TestRunner, err error) {
func (self *context) EnumerateRunners() (traceEvents []tapjio.TraceEvent, testRunners []runner.TestRunner, err error) {
var wg sync.WaitGroup
wg.Add(1)

Expand Down
5 changes: 5 additions & 0 deletions src/qa/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,8 @@ type Config struct {
func (f *Config) Files() ([]string, error) {
return f.FileLister.ListFiles()
}

type Context interface {
EnumerateRunners() ([]tapjio.TraceEvent, []TestRunner, error)
Close() error
}

0 comments on commit 7425d57

Please sign in to comment.