Skip to content

Instantly share code, notes, and snippets.

@cjeon
Created February 9, 2021 00:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjeon/7c676d299fe3b78ea5ca07ddb647a271 to your computer and use it in GitHub Desktop.
Save cjeon/7c676d299fe3b78ea5ca07ddb647a271 to your computer and use it in GitHub Desktop.
from google.oauth2 import service_account
import googleapiclient.discovery
SCOPES = ['https://www.googleapis.com/auth/cloud-platform']
credentials = service_account.Credentials.from_service_account_info(
loads(YOUR_FIREBASE_CREDENTIAL_HERE,
scopes=SCOPES
)
testing = googleapiclient.discovery.build('testing', 'v1', credentials=credentials)
results = googleapiclient.discovery.build('toolresults', 'v1beta3', credentials=credentials)
testMatrix = testing.projects().testMatrices().create(projectId=PROJECT_ID,
body=testMatrix).execute()
testMatrix = {
"clientInfo": {
"name": "firebase.py v1.0.0", # optional and only for logging purpose only.
"clientInfoDetails": [
{
"key": "branch",
"value": getoutput("git rev-parse --abbrev-ref HEAD")
},
{
"key": "last commit",
"value": getoutput("git log --pretty=oneline --abbrev-commit -1")
},
],
},
"testSpecification": {
"testTimeout": "600s",
"disableVideoRecording": True,
"disablePerformanceMetrics": True,
"androidInstrumentationTest": {
"appApk": {"gcsPath": DUMMY_APK_PATH}, # bucket path for app apk. as we don't have an
# app, we just used dummy apk.
"testApk": {"gcsPath": INSTRUMENTATION_TEST_APK_PATH}, # bucket path for test apk.
"appPackageId": "com.sendbird.android.core",
"testPackageId": "com.sendbird.android.test",
"testRunnerClass": "android.support.test.runner.AndroidJUnitRunner",
"testTargets": [
"notPackage org.conscrypt"
],
"shardingOption": {
"uniformSharding": {
"numShards": 20 # we ran 20 devices in parallel. bigger number means higher cost
# and shorter runtime but it's not directly proportional.
}
}
}
},
"resultStorage": {
"googleCloudStorage": {
"gcsPath": PATH_NAME
}
},
"environmentMatrix": {
"androidMatrix": {
"androidModelIds": ["NexusLowRes"],
"androidVersionIds": ["28"],
"locales": ["en"],
"orientations": ["portrait"]
}
},
"flakyTestAttempts": 2, # when a test fails, we try 2 times more until we conclude it's a
# failure. Only the failed shard will be retried, not the whole test suite.
}
NON_FINAL_STATES = ["VALIDATING", "PENDING", "RUNNING"]
while testMatrix["state"] in NON_FINAL_STATES:
sleep(5)
# to prevent no output kill, print something.
print(".", end="", flush=True)
testMatrix = testing.projects().testMatrices() \
.get(projectId=PROJECT_ID, testMatrixId=testMatrix["testMatrixId"]).execute()
success = testMatrix["outcomeSummary"] == "SUCCESS"
if success:
print("Test SUCCESS!")
else:
print("Test FAILED!")
HISTORY_ID = testMatrix["testExecutions"][0]["toolResultsStep"]["historyId"]
EXECUTION_ID = testMatrix["testExecutions"][0]["toolResultsStep"]["executionId"]
steps = []
pageToken = None
while True:
response = results.projects().histories().executions().steps().list(
projectId=PROJECT_ID,
historyId=HISTORY_ID,
executionId=EXECUTION_ID,
pageToken=pageToken
).execute()
steps.extend(response['steps'])
if "nextPageToken" in response:
pageToken = response["nextPageToken"]
else:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment