Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reconciler: Add test case for the example #31

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: all build test test-race bench
.PHONY: all build test test-race test-example bench

all: build test test-race bench

Expand All @@ -7,6 +7,7 @@ build:

test:
go test ./... -cover -vet=all -test.count 1
./reconciler/example/test.sh

test-race:
go test -race ./... -test.count 1
Expand Down
1 change: 1 addition & 0 deletions reconciler/example/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
example
test.log
2 changes: 1 addition & 1 deletion reconciler/example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func NewReconcilerConfig(ops reconciler.Operations[*Memo], tbl statedb.RWTable[*
return reconciler.Config[*Memo]{
Table: tbl,
Metrics: m,
FullReconcilationInterval: 10 * time.Second,
FullReconcilationInterval: time.Second,
RetryBackoffMinDuration: 100 * time.Millisecond,
RetryBackoffMaxDuration: 5 * time.Second,
IncrementalRoundSize: 100,
Expand Down
57 changes: 57 additions & 0 deletions reconciler/example/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, not sure I'm super excited about a bash test case that doesn't run on go test ./...

What was the reasoning in not making this a Go test? ease of starting/stopping processes etc?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just the ease of writing it, but yeah that's a bit short sighted. Let's make this into a go test.

cd $SCRIPT_DIR

exec 3>&1
exec &> test.log

set -eux

go build .
./example &

PID=$!
cleanup() {
s=$?
set +eux
kill $PID
if [ "$s" -ne 0 ]; then
cat test.log >&3
echo "FAILED" >&3
else
echo "PASS" >&3
fi
kill -9 $PID
exit $s
}
trap 'cleanup' SIGINT SIGTERM EXIT

for i in 1 2 3 4 5; do
curl -q http://localhost:8080/statedb &>/dev/null && break
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this error out if it doesn't manage to come up soon enough?

sleep 0.5
done

: Insertion
curl -d 'hello world' http://localhost:8080/memos/test
for i in 1 2 3 4 5; do
test -f memos/test && break
sleep 0.5
done
test -f memos/test

: Full reconciliation
rm -f memos/test
for i in 1 2 3 4 5; do
test -f memos/test && break
sleep 1
done
test -f memos/test

: Deletion
curl -XDELETE http://localhost:8080/memos/test
for i in 1 2 3 4 5; do
test ! -f memos/test && break
sleep 0.5
done
test ! -f memos/test

Loading