Skip to content

Commit

Permalink
add mysql container and fix close
Browse files Browse the repository at this point in the history
  • Loading branch information
pascal-fischer committed Jan 18, 2025
1 parent 9258adb commit 5cffe78
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
32 changes: 26 additions & 6 deletions .github/workflows/golang-test-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion management/server/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit 5cffe78

Please sign in to comment.