Skip to content

Commit

Permalink
Add ability to run tests on random device pool from list
Browse files Browse the repository at this point in the history
  • Loading branch information
artemnikitin committed Jun 10, 2018
1 parent 3d6d5bc commit 8c333fe
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
12 changes: 10 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/ioutil"
"log"
"os"
"strings"

"github.com/artemnikitin/devicefarm-ci-tool/errors"
"github.com/artemnikitin/devicefarm-ci-tool/model"
Expand All @@ -24,6 +25,7 @@ var (
appPath = flag.String("app", "", "Path to an app")
testPath = flag.String("test", "", "Path to test app")
devicePool = flag.String("devices", "Top Devices", "Specify list of devices for tests")
randomDevicePool = flag.String("randomDevices", "", "List of device pools for random choice")
configJSON = flag.String("config", "", "Path to JSON config")
wait = flag.Bool("wait", false, "Wait for run end")
checkEvery = flag.Int("checkEvery", 5, "Specified time slice for checking status of run")
Expand Down Expand Up @@ -92,7 +94,7 @@ func runJob(client devicefarmiface.DeviceFarmAPI, config *model.RunConfig) ([]*m
}
}

if *ignoreUnavailableDevices {
if *ignoreUnavailableDevices && *wait {
pass = svc.IsTestRunPassIgnoringUnavailableDevices(runArn)
}

Expand All @@ -110,7 +112,13 @@ func getConfig() *model.RunConfig {
configFile = model.Transform(bytes)
}
if configFile.DevicePoolArn == "" && configFile.DevicePoolName == "" {
configFile.DevicePoolName = *devicePool
if *randomDevicePool != "" {
pools := strings.Split(*randomDevicePool, ",")
i := tools.Random(0, len(pools)-1)
configFile.DevicePoolName = pools[i]
} else {
configFile.DevicePoolName = *devicePool
}
}
if *runName != "" {
configFile.Name = *runName
Expand Down
8 changes: 8 additions & 0 deletions tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package tools
import (
"fmt"
"log"
"math/rand"
"strings"
"time"
)

// UploadFile used to upload file by S3 pre-signed URL
Expand Down Expand Up @@ -37,3 +39,9 @@ func GenerateReportURL(arn string) string {
run := str[index+1:]
return fmt.Sprintf(URL, project, run)
}

// Random generates random integer in given range
func Random(min, max int) int {
rand.Seed(time.Now().Unix())
return rand.Intn(max-min) + min
}
7 changes: 7 additions & 0 deletions tools/tools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,10 @@ func TestGenerateReportURL(t *testing.T) {
}
}
}

func TestRandom(t *testing.T) {
i := Random(1, 10)
if i < 1 || i > 10 {
t.Error("Random int should be in given range")
}
}

0 comments on commit 8c333fe

Please sign in to comment.