-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathtest_tail.sh
More file actions
executable file
·83 lines (56 loc) · 1.77 KB
/
Copy pathtest_tail.sh
File metadata and controls
executable file
·83 lines (56 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
# shellcheck disable=SC2064 # Intentional use of current script pid
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT
db=$(mktemp /tmp/db.XXXXXX)
tailfile=$(mktemp /tmp/tail.XXXXXX)
file1=$(mktemp /tmp/file.XXXXXX)
file2=$(mktemp /tmp/file.XXXXXX)
rm -Rf "$db" "$tailfile" "$file1" "$file2"
if [ -z "$SKDB_BIN" ]; then
if [ -z "$SKARGO_PROFILE" ]; then
SKARGO_PROFILE=dev
fi
SKDB_BIN="skargo run -q --profile $SKARGO_PROFILE -- "
fi
$SKDB_BIN --init "$db"
skdb="$SKDB_BIN --data $db"
cat privacy/init.sql | $skdb
echo "create table t1 (a INTEGER PRIMARY KEY);" | $skdb
echo "create table t2 (a INTEGER);" | $skdb
sessionID=$($skdb subscribe t1 --connect)
# Staring the tailer
tail -f /dev/null | $skdb tail "$sessionID" --follow > "$tailfile"&
tailerID=$!
# First let's insert something
echo "insert into t1 values(0);" | $skdb
# And make sure that the tailer picked it up
while ! grep "0" "$tailfile" -q > /dev/null; do
sleep 1
done
# Next, let's put the tailer to sleep
kill -TSTP $tailerID
# Now let's insert/remove a lot of data to force a purge
for i in {1..1000}; do
echo "insert into t1 values($i);"
done | $skdb
for i in {0..900}; do
echo "delete from t1 where a = $i;"
done | $skdb
# Now, let's wake up the process
kill -CONT $tailerID
# Let's make sure a purge actually occurred.
while ! cat "$tailfile" | tr '\t' 'Y' | grep 'YY' -q > /dev/null; do
sleep 1
done
cat "$tailfile" | $skdb write-csv > /dev/null
echo "select * from t1;" | $skdb > "$file1"
echo "select * from t2;" | $skdb > "$file2"
diff "$file1" "$file2" > /dev/null
if [ $? -eq 0 ]; then
echo "PURGE TEST: OK"
else
echo "PURGE TEST: FAILED"
fi
rm -Rf "$db" "$tailfile" "$file1" "$file2"
jobs -rp | xargs kill
jobs -rp | xargs wait 2>/dev/null