Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use stagemole with e2e tests #7343

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions .github/workflows/android-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,22 @@ on:
type: boolean
required: false
mockapi_test_repeat:
description: Mockapi test repeat(self hosted)
description: Mockapi test repeat (self hosted)
default: '1'
required: true
type: string
e2e_test_repeat:
description: e2e test repeat(self hosted)
description: e2e test repeat (self hosted)
default: '0'
required: true
type: string
e2e_tests_infra_flavor:
description: >
Infra environment to run e2e tests on (prod/stagemole).
If set to 'stagemole' test-related artefacts will be uploaded.
default: 'stagemole'
required: true
type: string
# Build if main is updated to ensure up-to-date caches are available
push:
branches: [main]
Expand Down Expand Up @@ -338,7 +345,9 @@ jobs:

- name: Build stagemole app
uses: burrunan/gradle-cache-action@v1
if: github.event.inputs.run_firebase_tests == 'true'
if: >
(github.event.inputs.e2e_test_repeat != '0' && github.event.inputs.e2e_tests_infra_flavor == 'stagemole') ||
github.event.inputs.run_firebase_tests == 'true'
with:
job-id: jdk17
arguments: |
Expand Down Expand Up @@ -530,7 +539,7 @@ jobs:

- name: Calculate timeout
id: calculate-timeout
run: echo "timeout=$(( ${{ matrix.test-repeat }} * 10 ))" >> $GITHUB_OUTPUT
run: echo "timeout=$(( ${{ matrix.test-repeat }} * 15 ))" >> $GITHUB_OUTPUT
shell: bash

- name: Run instrumented test script
Expand All @@ -540,15 +549,27 @@ jobs:
env:
AUTO_FETCH_TEST_HELPER_APKS: true
TEST_TYPE: e2e
BILLING_FLAVOR: oss
INFRA_FLAVOR: prod
VALID_TEST_ACCOUNT_NUMBER: ${{ secrets.ANDROID_PROD_TEST_ACCOUNT }}
BILLING_FLAVOR: ${{ github.event.inputs.e2e_tests_infra_flavor == 'prod' && 'oss' || 'play' }}
INFRA_FLAVOR: ${{ github.event.inputs.e2e_tests_infra_flavor }}
PARTNER_AUTH: |-
${{ github.event.inputs.e2e_tests_infra_flavor == 'stagemole' && secrets.STAGEMOLE_PARTNER_AUTH || '' }}
VALID_TEST_ACCOUNT_NUMBER: |-
${{ github.event.inputs.e2e_tests_infra_flavor == 'prod' && secrets.ANDROID_PROD_TEST_ACCOUNT || '' }}
INVALID_TEST_ACCOUNT_NUMBER: '0000000000000000'
ENABLE_HIGHLY_RATE_LIMITED_TESTS: ${{ github.event_name == 'schedule' && 'true' || 'false' }}
ENABLE_ACCESS_TO_LOCAL_API_TESTS: true
REPORT_DIR: ${{ steps.prepare-report-dir.outputs.report_dir }}
run: ./android/scripts/run-instrumented-tests-repeat.sh ${{ matrix.test-repeat }}

- name: Upload e2e instrumentation report
uses: actions/upload-artifact@v4
if: >
always() && matrix.test-repeat != 0 &&
github.event.inputs.e2e_tests_infra_flavor == 'stagemole'
with:
name: e2e-instrumentation-report
path: ${{ steps.prepare-report-dir.outputs.report_dir }}

firebase-tests:
name: Run firebase tests
if: github.event.inputs.run_firebase_tests == 'true'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AccountTestRule : BeforeEachCallback {
override fun beforeEach(context: ExtensionContext) {
InstrumentationRegistry.getArguments().also { bundle ->
if (partnerAuth != null) {
validAccountNumber = client.createAccount()
validAccountNumber = client.createAccount(partnerAuth)
client.addTimeToAccountUsingPartnerAuth(
accountNumber = validAccountNumber,
daysToAdd = 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import com.android.volley.toolbox.JsonObjectRequest
import com.android.volley.toolbox.RequestFuture
import com.android.volley.toolbox.StringRequest
import com.android.volley.toolbox.Volley
import net.mullvad.mullvadvpn.test.e2e.constant.ACCOUNT_URL
import net.mullvad.mullvadvpn.test.e2e.constant.AUTH_URL
import net.mullvad.mullvadvpn.test.e2e.constant.CONN_CHECK_URL
import net.mullvad.mullvadvpn.test.e2e.constant.DEVICE_LIST_URL
import net.mullvad.mullvadvpn.test.e2e.constant.PARTNER_ACCOUNT_URL
import org.json.JSONArray
import org.json.JSONObject
import org.junit.jupiter.api.fail

class SimpleMullvadHttpClient(context: Context) {

Expand All @@ -40,9 +40,13 @@ class SimpleMullvadHttpClient(context: Context) {
}
}

fun createAccount(): String {
return sendSimpleSynchronousRequest(method = Request.Method.POST, url = ACCOUNT_URL)!!
.getString("number")
fun createAccount(partnerAuth: String): String {
return sendSimpleSynchronousRequest(
method = Request.Method.POST,
url = PARTNER_ACCOUNT_URL,
authorizationHeader = partnerAuth
)!!
.getString("id")
}

fun addTimeToAccountUsingPartnerAuth(
Expand Down Expand Up @@ -201,6 +205,10 @@ class SimpleMullvadHttpClient(context: Context) {

private val onErrorResponse = { error: VolleyError ->
if (error.networkResponse != null) {
if (error.networkResponse.statusCode == 429) {
fail("Request failed with response status code 429: Too many requests")
}

Logger.e(
"Response returned error message: ${error.message} " +
"status code: ${error.networkResponse.statusCode}"
Expand Down
Loading