randomized-test-ci

 1#!/bin/bash
 2
 3set -u
 4
 5: $ZED_SERVER_URL
 6: $ZED_CLIENT_SECRET_TOKEN
 7
 8# Compile the tests first
 9mkdir -p target
10cargo test --release --lib --package collab --no-run
11if [[ $? != 0 ]]; then
12  echo "Build failed"
13  exit 1
14fi
15
16LOG_FILE=target/randomized-tests.log
17export SAVE_PLAN=target/test-plan.json
18export OPERATIONS=200
19export ITERATIONS=100000
20export SEED=$(od -A n -N 8 -t u8 /dev/urandom | xargs)
21
22echo "Starting seed: ${SEED}"
23
24cargo test --release --lib --package collab random 2>&1 > $LOG_FILE
25if [[ $? == 0 ]]; then
26  echo "Tests passed"
27  exit 0
28fi
29
30# If the tests failed, find the failing seed in the logs
31commit=$(git rev-parse HEAD)
32failing_seed=$(grep "failing seed" $LOG_FILE | tail -n1 | cut -d: -f2 | xargs)
33failing_plan=$(cat $SAVE_PLAN)
34request="{
35  \"seed\": \"${failing_seed}\",
36  \"commit\": \"${commit}\",
37  \"token\": \"${ZED_CLIENT_SECRET_TOKEN}\",
38  \"plan\": ${failing_plan}
39}"
40
41echo "Reporting test failure."
42echo $request
43
44curl \
45    -X POST \
46    -H "Content-Type: application/json" \
47    -d "${request}" \
48    "${ZED_SERVER_URL}/api/randomized_test_failure"