magnusbaeck / logstash-filter-verifier

Apache License 2.0
191 stars 27 forks source link

Run test in daemon mode as a single command (start + run) #183

Open oneingan opened 2 years ago

oneingan commented 2 years ago

I'd like to incorporate testing framework into automatic dev workflow (CI/CD pipeline, Git pre-hook script, Makefile and more). Do you have any hint about how I may launch tests? Or maybe I need a workaround wrapper command which: 1. start daemon, 2. run tests, 3. stop daemon?

something like logstash-filter-verifier daemon run --start-daemon --stop-daemon option will be huge.

Regards and thanks for your work. Be able to test pipeline-to-pipeline complex designs is amazing!

jgough commented 2 years ago

In our CI in Gitlab I run our tests in a docker container with something along these lines:

docker run --rm -d --name logstash-filter-verifier-$CI-COMMIT_SHA my-logstash-image daemon start
sleep 10
docker exec logstash-filter-verifier-$CI-COMMIT_SHA daemon run ...

The stopping is dealt with by Gitlab. Not ideal but it does work.

oneingan commented 2 years ago

My 2 cents

#!/usr/bin/env bash

TMPDIR=$(mktemp -d)

(logstash-filter-verifier daemon start \
        --socket "$TMPDIR"/logstash-filter-verifier.sock \
    --logstash-path /path/to/logstash \
        --keep-env PATH 2>&1 &) | grep -q "Ready to process tests"

logstash-filter-verifier "$@" --socket "$TMPDIR"/logstash-filter-verifier.sock
sleep 2
logstash-filter-verifier daemon shutdown --socket "$TMPDIR"/logstash-filter-verifier.sock
rm -rf "$TMPDIR"