Skip to content

Commit

Permalink
Ensure ability to run w/out partition when partition configured (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonywok authored Apr 26, 2023
1 parent 149a1c9 commit c61c8dc
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 15 deletions.
3 changes: 1 addition & 2 deletions internal/cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ func (rc RunConfig) MaxTestsToRetryPercentage() (*float64, error) {

func (rc RunConfig) IsRunningPartition() bool {
// TODO: Should we have a bit somewhere that indicates provider defaulted?
return rc.PartitionCommandTemplate != "" &&
(rc.PartitionConfig.PartitionNodes.Index != -1 || rc.PartitionConfig.PartitionNodes.Total != -1)
return rc.PartitionCommandTemplate != "" && rc.PartitionConfig.PartitionNodes.Total >= 1
}

type PartitionConfig struct {
Expand Down
42 changes: 34 additions & 8 deletions internal/cli/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,35 @@ var _ = Describe("RunConfig", func() {
Expect(err.Error()).To(ContainSubstring("Unsupported partitioning setup"))
})

It("errs when partitioning and partition config has nonsense index", func() {
err := cli.RunConfig{
PartitionCommandTemplate: "something {{ testFiles }}",
PartitionConfig: cli.PartitionConfig{
SuiteID: "your-suite",
PartitionNodes: config.PartitionNodes{
Index: -1,
Total: 1,
},
},
}.Validate()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("Missing partition index"))
})

It("is not an error when partitioning is configured but not currently partitioning", func() {
err := cli.RunConfig{
PartitionCommandTemplate: "something {{ testFiles }}",
PartitionConfig: cli.PartitionConfig{
SuiteID: "your-suite",
PartitionNodes: config.PartitionNodes{
Index: -1,
Total: -1,
},
},
}.Validate()
Expect(err).NotTo(HaveOccurred())
})

It("is valid when partitioning and partition config has command and globs", func() {
err := cli.RunConfig{
PartitionCommandTemplate: "something {{ testFiles }}",
Expand Down Expand Up @@ -205,7 +234,7 @@ var _ = Describe("RunConfig", func() {
Expect(cli.RunConfig{}.IsRunningPartition()).To(Equal(false))
})

It("returns false when partition command template is set, but neither partition index nor total are set", func() {
It("returns false when partition command template is set, but partition nodes are defaulted to -1", func() {
rc := cli.RunConfig{
PartitionCommandTemplate: "bin/rspec {{testFiles}}",
PartitionConfig: cli.PartitionConfig{
Expand All @@ -218,23 +247,20 @@ var _ = Describe("RunConfig", func() {
Expect(rc.IsRunningPartition()).To(Equal(false))
})

It("returns true when partition command template and partition index is set", func() {
It("returns false when partition command template is set, but neither partition nodes are unset", func() {
rc := cli.RunConfig{
PartitionCommandTemplate: "bin/rspec {{testFiles}}",
PartitionConfig: cli.PartitionConfig{
PartitionNodes: config.PartitionNodes{
Index: 0,
},
},
PartitionConfig: cli.PartitionConfig{},
}
Expect(rc.IsRunningPartition()).To(Equal(true))
Expect(rc.IsRunningPartition()).To(Equal(false))
})

It("returns true when partition command template and partition total is set", func() {
rc := cli.RunConfig{
PartitionCommandTemplate: "bin/rspec {{testFiles}}",
PartitionConfig: cli.PartitionConfig{
PartitionNodes: config.PartitionNodes{
Index: 0,
Total: 2,
},
},
Expand Down
6 changes: 1 addition & 5 deletions internal/providers/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,7 @@ func Merge(into Provider, from Provider) Provider {
into.CommitMessage = firstNonempty(from.CommitMessage, into.CommitMessage)
into.Title = firstNonempty(from.Title, into.Title)

intoPartitionImplicitlyUnset := into.PartitionNodes == config.PartitionNodes{}
intoPartitionExplicitlyUnset := into.PartitionNodes.Index < 0 || into.PartitionNodes.Total < 0
fromPartitionExplicitlySet := from.PartitionNodes.Index >= 0 && from.PartitionNodes.Total >= 1

if fromPartitionExplicitlySet && (intoPartitionExplicitlyUnset || intoPartitionImplicitlyUnset) {
if into.PartitionNodes.Total <= 0 && from.PartitionNodes.Total >= 1 {
into.PartitionNodes = from.PartitionNodes
}

Expand Down
16 changes: 16 additions & 0 deletions test/oss_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,22 @@ var _ = Describe(versionedPrefixForQuarantining()+"OSS mode Integration Tests",
Expect(result.exitCode).To(Equal(0))
})
})

Context("when partitioning is configured but flags aren't provided", func() {
It("runs the default run command", func() {
result := runCaptain(captainArgs{
args: []string{
"run",
"oss-run-with-partition",
"--config-file", "fixtures/integration-tests/partition-config.yaml",
},
env: make(map[string]string),
})

Expect(result.exitCode).To(Equal(123))
Expect(result.stdout).To(Equal("default run"))
})
})
})

Describe("captain run w/ partition", func() {
Expand Down

0 comments on commit c61c8dc

Please sign in to comment.