Skip to content

Commit

Permalink
Wait for daemon start if it is down
Browse files Browse the repository at this point in the history
When we get adb restart "error" we'd like to keep polling as it is a recoverable state.

* Migrate to go modules and remove legacy code.
* Implement new bitrise.yml structure.
* Restructure e2e tests and add daemon_restart workflow.
* Wire in stepconf package for Step Input handling.
* Do not fail on adb daemon restart error.
* Fix emulator params.
* Fix device boot check loop.
  • Loading branch information
godrei authored Jun 24, 2021
1 parent 9654515 commit 0f5ab61
Show file tree
Hide file tree
Showing 42 changed files with 2,950 additions and 423 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.bitrise*
.gows*
_tmp
_tmp
35 changes: 0 additions & 35 deletions CHANGELOG.md

This file was deleted.

38 changes: 0 additions & 38 deletions Godeps/Godeps.json

This file was deleted.

5 changes: 0 additions & 5 deletions Godeps/Readme

This file was deleted.

86 changes: 15 additions & 71 deletions bitrise.yml
Original file line number Diff line number Diff line change
@@ -1,86 +1,30 @@
format_version: 9
format_version: "11"
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git

workflows:
test:
before_run:
- audit-this-step
sample:
steps:
- go-list:
- golint:
- errcheck:
- go-test:
- change-workdir:
inputs:
- path: _tmp
- avd-manager:
title: Start Android Emulator
- path::./:
title: Wait for the emulator to boot
title: Wait for the Emulator boot
is_always_run: false
- script:
title: Stop Android Emulator
inputs:
- content: pkill -f qemu-system-i386
- script:
title: Create hanging adb
inputs:
- content: |-
#!/usr/bin/env bash
set -e
mkdir -p platform-tools
cat /dev/null > adb_log
cat /dev/null > platform-tools/adb
cat >> platform-tools/adb <<'EOF'
#!/usr/bin/env bash

echo "$@" >> adb_log
[[ "$1" == "kill-server" ]] && exit 0
sleep 120
EOF
chmod +x platform-tools/adb
- path::./:
title: Should fail with timeout - Wait for the emulator to boot
is_always_run: false
is_skippable: true
inputs:
- boot_timeout: 60
- android_home: ./
- script:
title: check if commands are called
is_always_run: false
is_skippable: false
inputs:
- content: |-
#!/usr/bin/env bash
set -ex
[[ $(grep -c "kill-server" ./adb_log) == "3" ]] &&
[[ $(grep -c -- '-s emulator-5554 shell getprop dev.bootcomplete' ./adb_log) == "3" ]] ||
exit 1
# ----------------------------------------------------------------
# --- Utility workflows
dep-update:
title: Dep update
description: |
Used for updating bitrise dependencies with dep
check:
steps:
- script:
title: Dependency update
inputs:
- content: |-
#!/bin/bash
set -ex
go get -u -v github.com/golang/dep/cmd/dep
dep ensure -v
dep ensure -v -update
- git::https://github.com/bitrise-steplib/steps-check.git:

# ----------------------------------------------------------------
# --- workflows to Share this step into a Step Library
audit-this-step:
e2e:
steps:
- script:
inputs:
- content: |-
#!/usr/bin/env bash
set -ex
stepman audit --step-yml ./step.yml
- git::https://github.com/bitrise-steplib/steps-check.git:
inputs:
- workflow: e2e

test:
before_run:
- check
- e2e
106 changes: 106 additions & 0 deletions e2e/bitrise.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
format_version: "11"
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git

workflows:
test_smoke:
before_run:
- _start_emulator
steps:
- path::./:
title: Wait for the Emulator boot
is_always_run: false
after_run:
- _stop_emulators

test_hanging_adb:
steps:
- script:
title: Start a failing workflow, wrapped in a script
inputs:
- content: |-
#!/bin/env bash
set -x # Do not set -e as bitrise command is excepted to fail
bitrise run -c ./e2e/bitrise.yml utility_test_hanging_adb
if [ $? -ne 1 ] ; then
echo "Workflow was excepted to fail, but exit code is not 1"
exit 1
fi
utility_test_hanging_adb:
before_run:
- _start_emulator
steps:
- change-workdir:
title: Chnage workdir to ./_tmp
inputs:
- path: _tmp
- script:
title: Create hanging adb
inputs:
- content: |-
#!/usr/bin/env bash
set -e
mkdir -p platform-tools
cat /dev/null > adb_log
cat /dev/null > platform-tools/adb
cat >> platform-tools/adb <<'EOF'
#!/usr/bin/env bash
echo "$@" >> adb_log
[[ "$1" == "kill-server" ]] && exit 0
sleep 120
EOF
chmod +x platform-tools/adb
- path::./:
title: Wait for the emulator to boot - should fail with timeout
is_always_run: false
is_skippable: false
inputs:
- boot_timeout: 60
- android_home: ./
- script:
title: check if commands are called
is_always_run: false
is_skippable: false
inputs:
- content: |-
#!/usr/bin/env bash
set -ex
[[ $(grep -c "kill-server" ./adb_log) == "3" ]] &&
[[ $(grep -c -- '-s emulator-5554 shell getprop dev.bootcomplete' ./adb_log) == "3" ]] ||
exit 1
after_run:
- _stop_emulators

test_daemon_restart:
before_run:
- _start_emulator
steps:
- script:
title: Stop Gradle daemon
inputs:
- content: |-
#!/bin/env bash
set -ex
$ANDROID_HOME/platform-tools/adb kill-server
- path::./:
title: Wait for the Emulator boot
after_run:
- _stop_emulators

_stop_emulators:
steps:
- script:
inputs:
- content: |-
#!/bin/env bash
adb devices | grep emulator | cut -f1 | while read line; do adb -s $line emu kill; done
_start_emulator:
steps:
- avd-manager:
title: Start Android Emulator
inputs:
- tag: default
- abi: x86_64
- api_level: 29
9 changes: 9 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module github.com/bitrise-steplib/steps-wait-for-android-emulator

go 1.16

require (
github.com/bitrise-io/go-android v0.0.0-20210527143215-3ad22ad02e2e
github.com/bitrise-io/go-steputils v0.0.0-20210527075147-910ce7a105a1
github.com/bitrise-io/go-utils v0.0.0-20210520073355-367fa34178f5
)
49 changes: 49 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
github.com/bitrise-io/go-android v0.0.0-20210527143215-3ad22ad02e2e h1:lkJnz+yXbIqFGpDTdRBBshqxeX0UCndJmEOp0yy2GRQ=
github.com/bitrise-io/go-android v0.0.0-20210527143215-3ad22ad02e2e/go.mod h1:gGXmY8hJ1x44AC98TIvZZvxP7o+hs4VI6wgmO4JMfEg=
github.com/bitrise-io/go-steputils v0.0.0-20210514150206-5b6261447e77/go.mod h1:H0iZjgsAR5NA6pnlD/zKB6AbxEsskq55pwJ9klVmP8w=
github.com/bitrise-io/go-steputils v0.0.0-20210527075147-910ce7a105a1 h1:gi29hTdxGXAGQvZckPZ9V8BAEfP3eK/tiZgTC5s6h1c=
github.com/bitrise-io/go-steputils v0.0.0-20210527075147-910ce7a105a1/go.mod h1:H0iZjgsAR5NA6pnlD/zKB6AbxEsskq55pwJ9klVmP8w=
github.com/bitrise-io/go-utils v0.0.0-20210507100250-37de47dfa6ce/go.mod h1:15EZZf02noI5nWFqXMZEoyb1CyqYRXTMz5Fyu4CWFzI=
github.com/bitrise-io/go-utils v0.0.0-20210520073355-367fa34178f5 h1:kclxBfygfNK6kWUB+9xcsfPLBen8Us9gubhitfL/Z6c=
github.com/bitrise-io/go-utils v0.0.0-20210520073355-367fa34178f5/go.mod h1:DRx7oFuAqk0dbKpAKCqWl0TgrowfJUb/MqYPRscxJOQ=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
github.com/hashicorp/go-retryablehttp v0.6.6/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
github.com/hashicorp/go-version v1.3.0 h1:McDWVJIU/y+u1BRV06dPaLfLCaT7fUTJLp5r04x7iNw=
github.com/hashicorp/go-version v1.3.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.3.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200219091948-cb0a6d8edb6c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210511113859-b0526f3d8744/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210503060354-a79de5458b56/go.mod h1:tfny5GFUkzUvx4ps4ajbZsCe5lw1metzhBm9T3x7oIY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
1 change: 0 additions & 1 deletion gows.yml

This file was deleted.

Loading

0 comments on commit 0f5ab61

Please sign in to comment.