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
17MIN_PLAN=target/test-plan.min.json
18export SAVE_PLAN=target/test-plan.json
19export OPERATIONS=200
20export ITERATIONS=100000
21export SEED=$(od -A n -N 8 -t u8 /dev/urandom | xargs)
22
23echo "Starting seed: ${SEED}"
24
25cargo test --release --lib --package collab random 2>&1 > $LOG_FILE
26if [[ $? == 0 ]]; then
27  echo "Tests passed"
28  exit 0
29fi
30
31failing_seed=$(script/randomized-test-minimize $SAVE_PLAN $MIN_PLAN)
32
33# If the tests failed, find the failing seed in the logs
34commit=$(git rev-parse HEAD)
35failing_plan=$(cat $MIN_PLAN)
36request="{
37  \"seed\": \"${failing_seed}\",
38  \"commit\": \"${commit}\",
39  \"token\": \"${ZED_CLIENT_SECRET_TOKEN}\",
40  \"plan\": ${failing_plan}
41}"
42
43echo "Reporting test failure."
44echo $request
45
46curl \
47    -X POST \
48    -H "Content-Type: application/json" \
49    -d "${request}" \
50    "${ZED_SERVER_URL}/api/randomized_test_failure"