From 77dc29308f8008baa4e210c43ace3c0f718c2f8a Mon Sep 17 00:00:00 2001 From: Martin Kraft Date: Mon, 23 Aug 2021 09:45:07 -0400 Subject: [PATCH] Fix for test-data make target (#18229) * Fix for the test-data command. * Sleep and warn about needing local mode enabled. * Improved server start synchro. --- Makefile | 12 +++++++++--- scripts/wait-for-system-start.sh | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) create mode 100755 scripts/wait-for-system-start.sh diff --git a/Makefile b/Makefile index beb954819f3..e2798cdcc12 100644 --- a/Makefile +++ b/Makefile @@ -425,9 +425,15 @@ cover: ## Runs the golang coverage tool. You must run the unit tests first. $(GO) tool cover -html=cover.out $(GO) tool cover -html=ecover.out -test-data: start-docker ## Add test data to the local instance. - $(GO) run $(GOFLAGS) -ldflags '$(LDFLAGS)' $(PLATFORM_FILES) config set TeamSettings.MaxUsersPerTeam 100 - $(GO) run $(GOFLAGS) -ldflags '$(LDFLAGS)' $(PLATFORM_FILES) sampledata -w 4 -u 60 +test-data: run-server ## Add test data to the local instance. + @if ! ./scripts/wait-for-system-start.sh; then \ + make stop; \ + fi + + @echo ServiceSettings.EnableLocalMode must be set to true. + + bin/mmctl config set TeamSettings.MaxUsersPerTeam 100 --local + bin/mmctl sampledata -u 60 --local @echo You may need to restart the Mattermost server before using the following @echo ======================================================================== diff --git a/scripts/wait-for-system-start.sh b/scripts/wait-for-system-start.sh new file mode 100755 index 00000000000..109ce4c7208 --- /dev/null +++ b/scripts/wait-for-system-start.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +total=0 +max_wait_seconds=60 + +echo "waiting $max_wait_seconds seconds for the server to start" + +while [[ "$total" -le "$max_wait_seconds" ]]; do + if bin/mmctl system status --local 2> /dev/null; then + exit 0 + else + ((total=total+1)) + printf "." + sleep 1 + fi +done + +printf "\nserver didn't start in $max_wait_seconds seconds\n" + +exit 1 \ No newline at end of file