End-to-End Tests
Teraslice End-to-End Test Suite
Dependencies
- Docker (not sure about minimal version but tested with 17.06.1-ce-rc1)
- Docker Compose (not sure about minimal version but tested with 1.14.0)
General Notes
Unless specified, all commands are assumed to be run from this e2e tests
directory - utils like docker-compose look for files in current dir.
You can run pnpm test from the directory to run the tests.
Development
When in dev mode, the teraslice project root will be built in a docker container, including any uncommitted changes. Currently this e2e tests do not support symlinked directories. The recommended workflow is:
-
From the teraslice project root,
pnpm run setupand it will link the teraslice packages together -
From the e2e directory,
pnpm testwill run the test suite against latest stable versions. -
Repeat as needed. When done, run
pnpm cleanfrom this directory.
CI Tests
When in CI, the teraslice tests will run until a failure happens then bail, output the logs, and cleanup the docker stack. To run in CI tests, use pnpm test:ci from inside the e2e directory from inside the project root. Running the CI tests will also force downloading assets.
Assets
Currently only the elasticsearch-assets and kafka-assets are automatically downloaded to the latest bundle and loaded into ${root}/e2e/autoload when the tests are ran. When downloading it will delete any older assets in order to prevent loading two different versions of the same asset.
To add additionally asset bundles, edit ${root}/e2e/test/download-assets.js.
Trouble-Shooting
The environment is managed by docker-compose. See the ps & log
sub-commands to diagnose potential issues in the containers. Here is a recipe to
prettify the teraslice logs:
# from this directory
pnpm logs
# if you want to follow the logs use:
pnpm logs-follow
Logging
E2e tests span two separate runtime environments, each with its own signale instance and logging behavior. Understanding this boundary is important when adding or debugging log output.
The two environments
ts-scripts process — the orchestration layer that builds the Docker image, starts services, and spawns Jest. Its signale instance is defined in packages/scripts/src/helpers/signale.ts:
logLevel: isTest ? 'error' : 'info'
isTest is process.env.NODE_ENV === 'test'. When ts-scripts runs its own unit tests it becomes 'error', but during a normal pnpm test --suite e2e invocation NODE_ENV is not 'test' in the ts-scripts process, so logLevel is 'info'.
e2e/Jest process — the child process spawned by ts-scripts that runs all files under e2e/test/. Its signale instance is defined in e2e/test/signale.ts:
logLevel: 'info'
This is hardcoded and does not change, even though Jest sets NODE_ENV=test in the child process. This is intentional: it means e2e test code can use signale.info(), signale.warn(), etc. unconditionally and the output will always be visible.
Why scripts debug calls are silent by default
Inside ts-scripts, there are two kinds of debug output:
-
signale.debug()calls with explicit guards — Many calls are wrapped inif (debug)orif (options.debug || options.trace || isCI). These only execute when--debugis passed. -
debugLoggercalls (const logger = debugLogger('ts-scripts:...')) — These use thedebugnpm package under the hood. Output is only produced when theDEBUGenvironment variable matches the namespace (e.g.DEBUG='*teraslice*'). WithoutDEBUGset, alllogger.debug(),logger.info(), and evenlogger.warn()calls fromdebugLoggerare completely silent.
What --debug enables
Passing --debug to ts-scripts (e.g. pnpm test --suite e2e --debug) does three things:
- Removes
--silentfrom Jest and adds--runInBand(sequential execution). - Sets
DEBUG='*teraslice*'in the child Jest environment, enabling alldebugLoggernamespaces that start withteraslice:. - Sets
DEBUG_LOG_LEVEL='debug'in the child Jest environment.
The DEBUG and DEBUG_LOG_LEVEL variables are forwarded only to the spawned Jest process, not back to the ts-scripts process itself.
Terafoundation logs inside containers
The Teraslice processes running inside Docker containers use a Bunyan-based logger configured in e2e/test/setup-config.ts:
log_level: [
{ console: 'warn' },
{ file: DEBUG_LOG_LEVEL || 'info' }
]
- Console output from containers is always at
'warn'level — only warnings and errors appear in container stdout/stderr. - File output defaults to
'info'. When--debugis passed,DEBUG_LOG_LEVEL='debug'is forwarded into the container environment and file logs become'debug'-level. - File logging is only active when
FILE_LOGGING=true, which ts-scripts sets via the--logsflag.
To view file logs from a running e2e run, use:
# from the e2e directory
pnpm logs
pnpm logs-follow
Adding new log calls in e2e code
- In
e2e/test/: use the e2e signale directly.signale.info()/.warn()/.error()are always visible.signale.debug()calls for the customdebugtype may be filtered depending on signale's logLevel. Prefersignale.info()for anything that should always appear during a test run. - In
packages/scripts/src/: wrap anysignale.debug()call that should only appear in debug mode with an explicitif (debug)guard. FordebugLoggercalls, output is only visible whenDEBUG=*teraslice*is set (i.e. when--debugis passed).
Notes
-
Teraslice will attempt to listen on port
45678, make sure to stop an local instance to prevent port collisions -
The port for docker's opensearch instance listens on
49200, so you can check it atlocalhost:49200