Skip to content

Unit Tests MUST NOT Access External Services (eg redis) #681

Description

@hiddenalpha

Expected behavior:
Unit tests do NOT require external services. If they do, they are integration tests and can be run when explicitly told to do so.

Actual behavior:
There are some unit test which require external services (redis in this case). So they are an integration test by definition...

Error Message (filtered):

[INFO] Running org.swisspush.gateleen.core.lock.lua.ReleaseLockLuaScriptTests
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.021 s <<< FAILURE! - in org.swisspush.gateleen.core.lock.lua.ReleaseLockLuaScriptTests
[ERROR] org.swisspush.gateleen.core.lock.lua.ReleaseLockLuaScriptTests  Time elapsed: 0.007 s  <<< ERROR!
redis.clients.jedis.exceptions.JedisConnectionException: Failed to create socket.
Caused by: java.net.ConnectException: Connection refused
...
[ERROR] Errors: 
[ERROR]   ReleaseLockLuaScriptTests>AbstractLuaScriptTest.checkRedisAvailable:24 » JedisConnection
...
[INFO] gateleen ........................................... SUCCESS [  0.481 s]
[INFO] gateleen-testhelper ................................ SUCCESS [  2.125 s]
[INFO] gateleen-core ...................................... FAILURE [ 12.595 s]
...
[INFO] BUILD FAILURE
...
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M5:test (default-test) on project gateleen-core: There are test failures.
...

Reproducer:

#!/bin/sh
set -e \
  && SUDO=sudo \
  && gateleenGitTag="v2.1.27" \
  && workDir="/home/user/work" \
  && cacheDir="/var/tmp" \
  \
  && $SUDO apt update \
  && $SUDO apt install --no-install-recommends -y \
         curl maven openjdk-21-jdk-headless \
  \
  && curl -SL https://github.com/swisspush/gateleen/archive/refs/tags/"${gateleenGitTag:?}".tar.gz > "${cacheDir:?}/gateleen-${gateleenGitTag:?}.tgz" \
  && mkdir -p "${workDir:?}/gateleen" \
  && cd       "${workDir:?}/gateleen" \
  && tar --strip-components 1 -xf "${cacheDir:?}/gateleen-${gateleenGitTag:?}.tgz" \
  && mvn clean \
  && mvn verify -PpublicRepos \

Why I consider this to be a bug:
It is crazy annoying, everytime one builds gateleen locally, it either: Does not work due to not running redis, or even worse: It enbloatens the local redis with unwanted test data. At times, it also triggers weird side-effects as other redis clients now may see their state corrupted.
Or for short: Stuff that requires ugly workarounds, is a bug.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions