-
Notifications
You must be signed in to change notification settings - Fork 1
/
test
executable file
·139 lines (111 loc) · 4.83 KB
/
test
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/env sh
set -e
# kill whole process group on exit
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT
# test publisher
rm -rf scratch
mkdir scratch
mkdir scratch/logger-out
mkdir scratch/zig-irc-logs
mkdir scratch/zig-irc-logs-origin
git -C scratch/zig-irc-logs init
git -C scratch/zig-irc-logs commit --allow-empty -m "initial commit"
git -C scratch/zig-irc-logs-origin init --bare
git -C scratch/zig-irc-logs remote add origin $(readlink -f scratch/zig-irc-logs-origin)
function addMsg() {
num=$1
timestamp=$2
from=$3
msg="$4"
echo $timestamp > scratch/logger-out/${num}.partial
echo "$from" >> scratch/logger-out/${num}.partial
printf "$msg" >> scratch/logger-out/${num}.partial
mv scratch/logger-out/${num}.partial scratch/logger-out/${num}
}
function waitWhile() {
while "$@"; do
sleep 0.1
done
}
function waitUntil() {
while true; do
if "$@"; then
break
fi
sleep 0.1
done
}
function testBadFilename() {
bad_filename=$1
expected_error=$2
#rm scratch/publisher.badfilename.out
ln -s "$bad_filename" scratch/zig-irc-logs/now
zig build run-publisher -- --logger-dir scratch/logger-out --repo scratch/zig-irc-logs &> scratch/publisher.badfilename.out &
addMsg 0 1622782862 somebody "hello there"
waitUntil grep -q InvalidRepoDateFilename scratch/publisher.badfilename.out
if not grep "$expected_error" scratch/publisher.badfilename.out; then
echo "Error: missing expected output: $expected_error, got the following errors"
echo -----
grep "$error:" scratch/publisher.badfilename.out
echo -----
exit 1
fi
rm scratch/publisher.badfilename.out
unlink scratch/zig-irc-logs/now
}
testBadFilename a "filename 'a' does not end with '.txt'"
testBadFilename .txt "filename '.txt' is not long enough"
testBadFilename /01-01.txt "filename '/01-01.txt' is not long enough"
testBadFilename 1/01/01.txt "filename '1/01/01.txt' is missing '-' to separate month/day"
testBadFilename 1-01-01.txt "error: filename '1-01-01.txt' is missing '/' to separate year/month"
testBadFilename a/01-01.txt "filename 'a/01-01.txt' contains invalid year"
testBadFilename 1/00-01.txt "filename '1/00-01.txt' contains month 0 out of range"
testBadFilename 1/13-01.txt "filename '1/13-01.txt' contains month 13 out of range"
testBadFilename 1/01-aa.txt "filename '1/01-aa.txt' contains invalid day"
testBadFilename 1/01-00.txt "filename '1/01-00.txt' contains day 0 out of range"
testBadFilename 1/01-32.txt "filename '1/01-32.txt' contains invalid day"
zig build run-publisher -- --logger-dir scratch/logger-out --repo scratch/zig-irc-logs &> scratch/publisher.out &
publisher_pid=$!
addMsg 0 1622782862 fred "hello there"
waitWhile test -e scratch/logger-out/0
test -e scratch/zig-irc-logs/2021/06-04.txt
addMsg 0 1622782866 george "hi, how are you?"
waitWhile test -e scratch/logger-out/1
test -e scratch/zig-irc-logs/2021/06-04.txt
addMsg 0 1622782866 fred "I asked you first"
waitWhile test -e scratch/logger-out/2
test -e scratch/zig-irc-logs/2021/06-04.txt
# the order in which we receive messages is more important than the timestamp
# so if the timestamp is from the past, just shove it in the log anyway
# the client can deal with how to interpret the timestamps
addMsg 0 10 fred "what's goin on here, I'm a time traveler from 1970"
waitWhile test -e scratch/logger-out/3
test -e scratch/zig-irc-logs/2021/06-04.txt
waitUntil grep -q "time traveler" scratch/zig-irc-logs/2021/06-04.txt
# test a very old message
#addMsg 0 1522992862 anotherbody "hi, how are you?"
# note: this is ok now, I just put the message in the current day even though
# the timestamp is clearly messed up
# zig-irc-logger prioritizes receive order over timestamp
#waitUntil grep TimestampsMessedUp scratch/publisher.out
addMsg 0 2522992862 anotherbody "whoa, it's been a while"
waitUntil test -e scratch/zig-irc-logs/2049/12-13.txt
git clone scratch/zig-irc-logs-origin scratch/zig-irc-logs-cloned
test -e scratch/zig-irc-logs-cloned/2021/06-04.txt
# remove the new log file so we can test what would happen if the 'now' link
# was created but we failed to write the log file
git -C scratch/zig-irc-logs reset --soft HEAD^1
git -C scratch/zig-irc-logs rm -f 2049/12-13.txt
addMsg 0 2532992862 joe "yeah it has"
waitUntil test -e scratch/zig-irc-logs/2050/04-08.txt
sleep 1
# start publisher again because it should have crashed
#zig build run-publisher -- --logger-dir scratch/logger-out --repo scratch/zig-irc-logs &> scratch/publisher2.out &
#publisher_pid=$!
#rm -rf scratch/zig-irc-logs/2021
#addMsg 0 1622782862 somebody "hello?"
#waitWhile test -e scratch/logger-out/0
#addMsg 1 1622782862 somebody "is anyone there?"
#waitWhile test -e scratch/logger-out/1
echo --------------------------------------------------------------------------------
echo Success