diff --git a/.github/workflows/golang-test-linux.yml b/.github/workflows/golang-test-linux.yml index c941b0b8696..48390c0d787 100644 --- a/.github/workflows/golang-test-linux.yml +++ b/.github/workflows/golang-test-linux.yml @@ -215,21 +215,41 @@ jobs: sleep 3 done + - name: Start MySQL + if: matrix.store == 'mysql' + run: | + docker run -d \ + -e MYSQL_ROOT_PASSWORD=netbird \ + -e MYSQL_DATABASE=netbird \ + -p 3306:3306 \ + --name my-mysql \ + mlsmaycon/warmed-mysql:8 + + - name: Wait for MySQL + if: matrix.store == 'mysql' + run: | + for i in {1..10}; do + if nc -z localhost 3306; then + break + fi + echo "Waiting for MySQL..." + sleep 3 + done + - name: Test run: | - # For Postgres: pass DSN, etc. if [ "${{ matrix.store }}" = "postgres" ]; then export NETBIRD_STORE_ENGINE_POSTGRES_DSN="postgres://root:netbird@localhost:5432/netbird?sslmode=disable" fi + + if [ "${{ matrix.store }}" = "mysql" ]; then + export NETBIRD_STORE_ENGINE_MYSQL_DSN="root:netbird@tcp(localhost:3306)/netbird?parseTime=True" + fi - # For MySQL: maybe do `docker run ...` similarly or skip entirely - # For SQLite: no container - - # run tests CGO_ENABLED=1 GOARCH=${{ matrix.arch }} \ NETBIRD_STORE_ENGINE=${{ matrix.store }} \ go test -tags=devcert -p 1 \ - -exec "sudo --preserve-env=CI,NETBIRD_STORE_ENGINE,NETBIRD_STORE_ENGINE_POSTGRES_DSN" \ + -exec "sudo --preserve-env=CI,NETBIRD_STORE_ENGINE,NETBIRD_STORE_ENGINE_POSTGRES_DSN, NETBIRD_STORE_ENGINE_MYSQL_DSN" \ -timeout 10m $(go list ./... | grep /management) benchmark: diff --git a/management/server/store/store.go b/management/server/store/store.go index 1f4f270d748..82d7806202e 100644 --- a/management/server/store/store.go +++ b/management/server/store/store.go @@ -430,9 +430,9 @@ func createRandomDB(dsn string, db *gorm.DB, cleanUp func(), removeContainer boo u.Path = dbName cleanup := func() { + db.Exec(fmt.Sprintf("DROP DATABASE %s WITH (FORCE)", dbName)) sqlDB, _ := db.DB() _ = sqlDB.Close() - db.Exec(fmt.Sprintf("DROP DATABASE %s WITH (FORCE)", dbName)) if cleanUp != nil && removeContainer { cleanUp() }