build(messaging): js script for detecting RabbitMQ container ready state
MODIFY
scripts/run-tests.sh
scripts/run-tests.sh
RABBITMQ_CONTAINER=marble-rabbit
-function wait_for_rabbit () {
- until docker exec $RABBITMQ_CONTAINER rabbitmqctl cluster_status > /dev/null 2>&1
- do
- sleep 2
- echo "Waiting for rabbitmq..."
- done
-}
-
docker-compose -f docker-compose.yml up -d
-wait_for_rabbit
+node scripts/wait.js
if [ "$SCOPE" == "unit" ]; then
jest --expand --coverage --detectOpenHandles

ADD
scripts/wait.js
+/* eslint-disable @typescript-eslint/no-var-requires */
+
+const amqplib = require('amqplib');
+const chalk = require('chalk').default;
+const SECOND = 1000;
+
+const log = msg => console.info(chalk.yellow(msg));
+
+const waitForRabbitMq = async () => {
+ try {
+ await amqplib.connect('amqp://localhost:5672');
+ process.exit();
+ } catch(err) {
+ log(' -- Waiting for RabbitMQ to by ready...');
+ setTimeout(() => waitForRabbitMq(), 5 * SECOND);
+ }
+}
+
+(async function() {
+ await waitForRabbitMq();
+})();

build(messaging): js script for detecting RabbitMQ container ready state