Debian Codegraph @

third_party/rust/glean/tests/test-delayed-ping-data.sh

raw
1 #!/bin/bash
2
3 # Test harness for testing the RLB processes from the outside.
4 #
5 # Some behavior can only be observed when properly exiting the process running Glean,
6 # e.g. when an uploader runs in another thread.
7 # On exit the threads will be killed, regardless of their state.
8
9 # Remove the temporary data path on all exit conditions
10 cleanup() {
11 if [ -n "$datapath" ]; then
12 rm -r "$datapath"
13 fi
14 }
15 trap cleanup INT ABRT TERM EXIT
16
17 tmp="${TMPDIR:-/tmp}"
18 datapath=$(mktemp -d "${tmp}/glean_ping_lifetime_flush.XXXX")
19
20 cmd="cargo run -p glean --example delayed-ping-data -- $datapath"
21
22 # First run "crashes" -> no increment stored
23 $cmd accumulate_one_and_pretend_crash
24 count=$(ls -1q "$datapath/sent_pings" | wc -l)
25 if [[ "$count" -ne 0 ]]; then
26 echo "test result: FAILED."
27 exit 101
28 fi
29
30 # Second run increments and orderly shuts down -> increment flushed to disk.
31 # No ping is sent.
32 $cmd accumulate_ten_and_orderly_shutdown
33 count=$(ls -1q "$datapath/sent_pings" | wc -l)
34 if [[ "$count" -ne 0 ]]; then
35 echo "1/3 test result: FAILED. Expected 0, got $count pings"
36 exit 101
37 fi
38
39 # Third run sends the ping.
40 $cmd submit_ping
41 count=$(ls -1q "$datapath/sent_pings" | wc -l)
42 if [[ "$count" -ne 1 ]]; then
43 echo "2/3 test result: FAILED. Expect 1, got $count pings"
44 exit 101
45 fi
46
47 if ! grep -q '"test.metrics.sample_counter":10' "$datapath"/sent_pings/*; then
48 echo "3/3 test result: FAILED. Inaccurate number of sample counts."
49 exit 101
50 fi
51
52 echo "test result: ok."
53 exit 0