Skip to content

Commit

Permalink
Merge pull request #298 from galasa-dev/mcobbett-exit-immediately-whe…
Browse files Browse the repository at this point in the history
…n-all-tests-done

mcobbett exit immediately when all tests done
  • Loading branch information
techcobweb authored Oct 24, 2024
2 parents bc0103c + 414fa23 commit 3e710bc
Show file tree
Hide file tree
Showing 16 changed files with 233 additions and 145 deletions.
2 changes: 1 addition & 1 deletion .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
"hashed_secret": "c042bdfc4bc5516ec716afe9e85c173b614ff9f5",
"is_secret": false,
"is_verified": false,
"line_number": 824,
"line_number": 829,
"type": "Hex High Entropy String",
"verified_result": null
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/cmd/runsSubmit.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func (cmd *RunsSubmitCommand) executeSubmit(
if err == nil {

timeService := factory.GetTimeService()
timedSleeper := utils.NewRealTimedSleeper()
var launcherInstance launcher.Launcher

// The launcher we are going to use to start/monitor tests.
Expand All @@ -190,7 +191,7 @@ func (cmd *RunsSubmitCommand) executeSubmit(

var console = factory.GetStdOutConsole()

submitter := runs.NewSubmitter(galasaHome, fileSystem, launcherInstance, timeService, env, console, images.NewImageExpanderNullImpl())
submitter := runs.NewSubmitter(galasaHome, fileSystem, launcherInstance, timeService, timedSleeper, env, console, images.NewImageExpanderNullImpl())

err = submitter.ExecuteSubmitRuns(cmd.values, cmd.values.TestSelectionFlagValues)
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/cmd/runsSubmitLocal.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ func (cmd *RunsSubmitLocalCommand) executeSubmitLocal(
if err == nil {

timeService := utils.NewRealTimeService()
timedSleeper := utils.NewRealTimedSleeper()

// the submit is targetting a local JVM
embeddedFileSystem := embedded.GetReadOnlyFileSystem()
Expand All @@ -205,7 +206,7 @@ func (cmd *RunsSubmitLocalCommand) executeSubmitLocal(
factory,
bootstrapData.Properties, embeddedFileSystem,
cmd.values.runsSubmitLocalCmdParams,
processFactory, galasaHome)
processFactory, galasaHome, timedSleeper)

if err == nil {
var console = factory.GetStdOutConsole()
Expand All @@ -219,6 +220,7 @@ func (cmd *RunsSubmitLocalCommand) executeSubmitLocal(
fileSystem,
launcherInstance,
timeService,
timedSleeper,
env,
console,
expander,
Expand Down
14 changes: 10 additions & 4 deletions pkg/launcher/jvmLauncher.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@ type JvmLauncher struct {
// The collection of tests which are running, or have completed.
localTests []*LocalTest

// This timer service can be interrupted when we don't want it to sleep.
// This timer service allows unit tests to control the time explicitly.
timeService spi.TimeService

// Used by the main polling loop to sleep and be interrupted.
timedSleeper spi.TimedSleeper

// A service which can create OS processes.
processFactory ProcessFactory

Expand Down Expand Up @@ -116,13 +119,16 @@ const (

// NewJVMLauncher creates a JVM launcher. Primes it with references to services
// which can be used to launch JVM servers.
// We get the caller's timer service so we can interrupt the caller when we are done.
func NewJVMLauncher(
factory spi.Factory,
bootstrapProps props.JavaProperties,
embeddedFileSystem embedded.ReadOnlyFileSystem,
runsSubmitLocalCmdParams *RunsSubmitLocalCmdParameters,
processFactory ProcessFactory,
galasaHome spi.GalasaHome,
timedSleeper spi.TimedSleeper,

) (*JvmLauncher, error) {

var (
Expand All @@ -132,7 +138,6 @@ func NewJVMLauncher(

env := factory.GetEnvironment()
fileSystem := factory.GetFileSystem()
timeService := factory.GetTimeService()

javaHome := env.GetEnv("JAVA_HOME")

Expand All @@ -148,7 +153,8 @@ func NewJVMLauncher(
launcher.embeddedFileSystem = embeddedFileSystem
launcher.processFactory = processFactory
launcher.galasaHome = galasaHome
launcher.timeService = timeService
launcher.timeService = factory.GetTimeService()
launcher.timedSleeper = timedSleeper
launcher.bootstrapProps = bootstrapProps

// Make sure the home folder has the boot jar unpacked and ready to invoke.
Expand Down Expand Up @@ -278,7 +284,7 @@ func (launcher *JvmLauncher) SubmitTestRun(
)
if err == nil {
log.Printf("Launching command '%s' '%v'\n", cmd, args)
localTest := NewLocalTest(launcher.timeService, launcher.fileSystem, launcher.processFactory)
localTest := NewLocalTest(launcher.timedSleeper, launcher.fileSystem, launcher.processFactory)
err = localTest.launch(cmd, args)

if err == nil {
Expand Down
63 changes: 35 additions & 28 deletions pkg/launcher/jvmLauncher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func NewMockLauncherParams() (
embedded.ReadOnlyFileSystem,
*RunsSubmitLocalCmdParameters,
spi.TimeService,
spi.TimedSleeper,
ProcessFactory,
spi.GalasaHome,
) {
Expand All @@ -74,13 +75,14 @@ func NewMockLauncherParams() (
galasaHome, _ := utils.NewGalasaHome(fs, env, "")
jvmLaunchParams := getBasicJvmLaunchParams()
timeService := utils.NewMockTimeService()
timedSleeper := utils.NewRealTimedSleeper()
mockProcess := NewMockProcess()
mockProcessFactory := NewMockProcessFactory(mockProcess)

bootstrapProps := getBasicBootstrapProperties()

return bootstrapProps, env, fs, embedded.GetReadOnlyFileSystem(),
jvmLaunchParams, timeService, mockProcessFactory, galasaHome
jvmLaunchParams, timeService, timedSleeper, mockProcessFactory, galasaHome
}

func TestCanCreateAJVMLauncher(t *testing.T) {
Expand All @@ -95,6 +97,7 @@ func TestCanCreateAJVMLauncher(t *testing.T) {

jvmLaunchParams := getBasicJvmLaunchParams()
timeService := utils.NewMockTimeService()
timedSleeper := utils.NewRealTimedSleeper()

mockProcess := NewMockProcess()
mockProcessFactory := NewMockProcessFactory(mockProcess)
Expand All @@ -110,7 +113,7 @@ func TestCanCreateAJVMLauncher(t *testing.T) {
launcher, err := NewJVMLauncher(
mockFactory,
bootstrapProps, embedded.GetReadOnlyFileSystem(),
jvmLaunchParams, mockProcessFactory, galasaHome,
jvmLaunchParams, mockProcessFactory, galasaHome, timedSleeper,
)
if err != nil {
assert.Fail(t, "Constructor should not have failed but it did. error:%s", err.Error())
Expand Down Expand Up @@ -146,6 +149,7 @@ func TestCantCreateAJVMLauncherIfJVMHomeNotSet(t *testing.T) {

jvmLaunchParams := getBasicJvmLaunchParams()
timeService := utils.NewMockTimeService()
timedSleeper := utils.NewRealTimedSleeper()

mockProcess := NewMockProcess()
mockProcessFactory := NewMockProcessFactory(mockProcess)
Expand All @@ -159,7 +163,7 @@ func TestCantCreateAJVMLauncherIfJVMHomeNotSet(t *testing.T) {
launcher, err := NewJVMLauncher(
mockFactory,
bootstrapProps, embedded.GetReadOnlyFileSystem(),
jvmLaunchParams, mockProcessFactory, galasaHome,
jvmLaunchParams, mockProcessFactory, galasaHome, timedSleeper,
)
if err == nil {
assert.Fail(t, "Constructor should have failed but it did not.")
Expand All @@ -177,6 +181,7 @@ func TestCanCreateJvmLauncher(t *testing.T) {

jvmLaunchParams := getBasicJvmLaunchParams()
timeService := utils.NewMockTimeService()
timedSleeper := utils.NewRealTimedSleeper()
mockProcess := NewMockProcess()
mockProcessFactory := NewMockProcessFactory(mockProcess)
galasaHome, _ := utils.NewGalasaHome(fs, env, "")
Expand All @@ -192,7 +197,7 @@ func TestCanCreateJvmLauncher(t *testing.T) {
launcher, err := NewJVMLauncher(
mockFactory,
bootstrapProps, embedded.GetReadOnlyFileSystem(),
jvmLaunchParams, mockProcessFactory, galasaHome,
jvmLaunchParams, mockProcessFactory, galasaHome, timedSleeper,
)

if err != nil {
Expand All @@ -204,7 +209,7 @@ func TestCanCreateJvmLauncher(t *testing.T) {
func TestCanLaunchLocalJvmTest(t *testing.T) {
// Given...
bootstrapProps, env, fs, embeddedReadOnlyFS,
jvmLaunchParams, timeService, mockProcessFactory, galasaHome := NewMockLauncherParams()
jvmLaunchParams, timeService, timedSleeper, mockProcessFactory, galasaHome := NewMockLauncherParams()

mockFactory := &utils.MockFactory{
Env: env,
Expand All @@ -215,7 +220,7 @@ func TestCanLaunchLocalJvmTest(t *testing.T) {
launcher, err := NewJVMLauncher(
mockFactory,
bootstrapProps, embeddedReadOnlyFS,
jvmLaunchParams, mockProcessFactory, galasaHome,
jvmLaunchParams, mockProcessFactory, galasaHome, timedSleeper,
)

if err != nil {
Expand Down Expand Up @@ -276,7 +281,7 @@ func TestCanGetRunGroupStatus(t *testing.T) {
launcher, err := NewJVMLauncher(
mockFactory,
bootstrapProps, embedded.GetReadOnlyFileSystem(),
jvmLaunchParams, mockProcessFactory, galasaHome,
jvmLaunchParams, mockProcessFactory, galasaHome, utils.NewRealTimedSleeper(),
)
if err != nil {
assert.Fail(t, "Launcher should have launched command OK")
Expand Down Expand Up @@ -413,7 +418,7 @@ func TestBadlyFormedObrFromProfileInfoCausesError(t *testing.T) {

// Given...
bootstrapProps, env, fs, embeddedReadOnlyFS,
jvmLaunchParams, timeService, mockProcessFactory, galasaHome := NewMockLauncherParams()
jvmLaunchParams, timeService, timedSleeper, mockProcessFactory, galasaHome := NewMockLauncherParams()

mockFactory := &utils.MockFactory{
Env: env,
Expand All @@ -424,7 +429,7 @@ func TestBadlyFormedObrFromProfileInfoCausesError(t *testing.T) {
launcher, _ := NewJVMLauncher(
mockFactory,
bootstrapProps, embeddedReadOnlyFS,
jvmLaunchParams, mockProcessFactory, galasaHome)
jvmLaunchParams, mockProcessFactory, galasaHome, timedSleeper)

isTraceEnabled := true
var overrides map[string]interface{} = make(map[string]interface{})
Expand Down Expand Up @@ -455,7 +460,7 @@ func TestNoObrsFromParameterOrProfileCausesError(t *testing.T) {

// Given...
bootstrapProps, env, fs, embeddedReadOnlyFS,
jvmLaunchParams, timeService, mockProcessFactory, galasaHome := NewMockLauncherParams()
jvmLaunchParams, timeService, timedSleeper, mockProcessFactory, galasaHome := NewMockLauncherParams()

mockFactory := &utils.MockFactory{
Env: env,
Expand All @@ -465,7 +470,7 @@ func TestNoObrsFromParameterOrProfileCausesError(t *testing.T) {
launcher, _ := NewJVMLauncher(
mockFactory,
bootstrapProps, embeddedReadOnlyFS,
jvmLaunchParams, mockProcessFactory, galasaHome)
jvmLaunchParams, mockProcessFactory, galasaHome, timedSleeper)

isTraceEnabled := true
var overrides map[string]interface{} = make(map[string]interface{})
Expand Down Expand Up @@ -1345,6 +1350,7 @@ func NewMockGherkinParams() (
embedded.ReadOnlyFileSystem,
*RunsSubmitLocalCmdParameters,
spi.TimeService,
spi.TimedSleeper,
ProcessFactory,
spi.GalasaHome,
) {
Expand All @@ -1362,13 +1368,13 @@ func NewMockGherkinParams() (
bootstrapProps := getBasicBootstrapProperties()

return bootstrapProps, env, fs, embedded.GetReadOnlyFileSystem(),
jvmLaunchParams, timeService, mockProcessFactory, galasaHome
jvmLaunchParams, timeService, utils.NewRealTimedSleeper(), mockProcessFactory, galasaHome
}

func TestCanLaunchLocalJvmGherkinTest(t *testing.T) {
// Given...
bootstrapProps, env, fs, embeddedReadOnlyFS,
jvmLaunchParams, timeService, mockProcessFactory, galasaHome := NewMockGherkinParams()
jvmLaunchParams, timeService, timedSleeper, mockProcessFactory, galasaHome := NewMockGherkinParams()

mockFactory := &utils.MockFactory{
Env: env,
Expand All @@ -1379,7 +1385,7 @@ func TestCanLaunchLocalJvmGherkinTest(t *testing.T) {
launcher, err := NewJVMLauncher(
mockFactory,
bootstrapProps, embeddedReadOnlyFS,
jvmLaunchParams, mockProcessFactory, galasaHome,
jvmLaunchParams, mockProcessFactory, galasaHome, timedSleeper,
)

if err != nil {
Expand Down Expand Up @@ -1416,7 +1422,7 @@ func TestCanLaunchLocalJvmGherkinTest(t *testing.T) {
func TestBadGherkinURLSuffixReturnsError(t *testing.T) {
// Given...
bootstrapProps, env, fs, embeddedReadOnlyFS,
jvmLaunchParams, timeService, mockProcessFactory, galasaHome := NewMockGherkinParams()
jvmLaunchParams, timeService, timedSleeper, mockProcessFactory, galasaHome := NewMockGherkinParams()

mockFactory := &utils.MockFactory{
Env: env,
Expand All @@ -1427,7 +1433,7 @@ func TestBadGherkinURLSuffixReturnsError(t *testing.T) {
launcher, err := NewJVMLauncher(
mockFactory,
bootstrapProps, embeddedReadOnlyFS,
jvmLaunchParams, mockProcessFactory, galasaHome,
jvmLaunchParams, mockProcessFactory, galasaHome, timedSleeper,
)
if err != nil {
assert.Fail(t, "JVM launcher should have been creatable.")
Expand Down Expand Up @@ -1458,7 +1464,7 @@ func TestBadGherkinURLSuffixReturnsError(t *testing.T) {
func TestBadGherkinURLPrefixReutrnsError(t *testing.T) {
// Given...
bootstrapProps, env, fs, embeddedReadOnlyFS,
jvmLaunchParams, timeService, mockProcessFactory, galasaHome := NewMockGherkinParams()
jvmLaunchParams, timeService, timedSleeper, mockProcessFactory, galasaHome := NewMockGherkinParams()

mockFactory := &utils.MockFactory{
Env: env,
Expand All @@ -1469,7 +1475,7 @@ func TestBadGherkinURLPrefixReutrnsError(t *testing.T) {
launcher, err := NewJVMLauncher(
mockFactory,
bootstrapProps, embeddedReadOnlyFS,
jvmLaunchParams, mockProcessFactory, galasaHome,
jvmLaunchParams, mockProcessFactory, galasaHome, timedSleeper,
)

if err != nil {
Expand Down Expand Up @@ -1505,7 +1511,7 @@ func TestSetTestStructureFromRasFileValidFileContentReturnsOk(t *testing.T) {
jsonFileName := "structure.json"

_, _, fs, _,
_, _, _, galasaHome := NewMockLauncherParams()
_, _, _, _, galasaHome := NewMockLauncherParams()

jsonFilePath := galasaHome.GetNativeFolderPath() + "/" + jsonFileName
fs.WriteTextFile(jsonFilePath, validStructureJsonFileContent)
Expand Down Expand Up @@ -1555,7 +1561,7 @@ func TestSetTestStructureFromRasFileInvalidFileContentReturnsError(t *testing.T)
]
}`
_, _, fs, _,
_, _, _, galasaHome := NewMockLauncherParams()
_, _, _, _, galasaHome := NewMockLauncherParams()

jsonFilePath := galasaHome.GetNativeFolderPath() + "/" + jsonFileName
fs.WriteTextFile(jsonFilePath, invalidStructureJsonFileContent)
Expand All @@ -1575,7 +1581,7 @@ func TestSetTestStructureFromRasFileEmptyFileContentReturnsError(t *testing.T) {
jsonFileName := "structure.json"

_, _, fs, _,
_, _, _, galasaHome := NewMockLauncherParams()
_, _, _, _, galasaHome := NewMockLauncherParams()

jsonFilePath := galasaHome.GetNativeFolderPath() + "/" + jsonFileName
fs.WriteTextFile(jsonFilePath, "")
Expand All @@ -1594,7 +1600,7 @@ func TestSetTestStructureFromRasFileInvalidFilePathReturnsError(t *testing.T) {
jsonFileName := "structure.json"

_, _, fs, _,
_, _, _, _ := NewMockLauncherParams()
_, _, _, _, _ := NewMockLauncherParams()

invalidJsonFilePath := "invalidJsonFilePath/" + jsonFileName

Expand All @@ -1609,9 +1615,9 @@ func TestSetTestStructureFromRasFileInvalidFilePathReturnsError(t *testing.T) {
func TestCreateRunFromLocalTestValidRasFolderPathReturnsOk(t *testing.T) {
//Given...
_, _, fs, _,
_, timeService, mockProcessFactory, galasaHome := NewMockLauncherParams()
_, _, timedSleeper, mockProcessFactory, galasaHome := NewMockLauncherParams()

localTest := NewLocalTest(timeService, fs, mockProcessFactory)
localTest := NewLocalTest(timedSleeper, fs, mockProcessFactory)
localTest.runId = "L0"
localTest.rasFolderPathUrl = galasaHome.GetNativeFolderPath()

Expand All @@ -1628,14 +1634,15 @@ func TestCreateRunFromLocalTestValidRasFolderPathReturnsOk(t *testing.T) {
assert.Equal(t, "dev.galasa.examples.banking.account", run.TestStructure.GetBundle())
assert.Equal(t, "Passed", run.TestStructure.GetResult())
assert.Equal(t, "simpleSampleTest", run.GetTestStructure().Methods[0].GetMethodName())
assert.Equal(t, "finished", run.TestStructure.GetStatus())
}

func TestCreateRunFromLocalTestInvalidRasFolderPathReturnsError(t *testing.T) {
//Given...
_, _, fs, _,
_, timeService, mockProcessFactory, _ := NewMockLauncherParams()
_, _, timedSleeper, mockProcessFactory, _ := NewMockLauncherParams()

localTest := NewLocalTest(timeService, fs, mockProcessFactory)
localTest := NewLocalTest(timedSleeper, fs, mockProcessFactory)
localTest.runId = "L0"
localTest.rasFolderPathUrl = ""

Expand All @@ -1650,7 +1657,7 @@ func TestCreateRunFromLocalTestInvalidRasFolderPathReturnsError(t *testing.T) {
func TestGetRunsByIdReturnsOk(t *testing.T) {
// Given...
bootstrapProps, env, fs, embeddedReadOnlyFS,
jvmLaunchParams, timeService, _, galasaHome := NewMockLauncherParams()
jvmLaunchParams, timeService, timedSleeper, _, galasaHome := NewMockLauncherParams()

mockProcess := NewMockProcess()
mockProcessFactory := NewMockProcessFactory(mockProcess)
Expand All @@ -1664,7 +1671,7 @@ func TestGetRunsByIdReturnsOk(t *testing.T) {
launcher, _ := NewJVMLauncher(
mockFactory,
bootstrapProps, embeddedReadOnlyFS,
jvmLaunchParams, mockProcessFactory, galasaHome,
jvmLaunchParams, mockProcessFactory, galasaHome, timedSleeper,
)

isTraceEnabled := true
Expand Down
Loading

0 comments on commit 3e710bc

Please sign in to comment.