fix: resolve race conditions and update golangci-lint config

- Fix TestCertificateHandler_Delete race condition:
  - Add WAL mode and busy_timeout to SQLite connection
  - Add sleep to allow background sync goroutine to complete
- Fix TestNotificationService_SendExternal_EdgeCases race condition:
  - Use atomic.Value for cross-goroutine string access
- Update .golangci.yml for version 2:
  - Add version field
  - Move linters-settings under linters.settings
  - Remove deprecated typecheck and gosimple linters
  - Update govet shadow check syntax
This commit is contained in:
Wikid82
2025-11-28 00:54:47 +00:00
parent 1a9c651efd
commit 72fd121bdb
3 changed files with 44 additions and 4 deletions

View File

@@ -133,7 +133,8 @@ func TestCertificateHandler_Upload(t *testing.T) {
func TestCertificateHandler_Delete(t *testing.T) {
// Setup
tmpDir := t.TempDir()
db, err := gorm.Open(sqlite.Open("file::memory:?cache=shared"), &gorm.Config{})
// Use WAL mode and busy timeout for better concurrency with race detector
db, err := gorm.Open(sqlite.Open("file::memory:?cache=shared&_journal_mode=WAL&_busy_timeout=5000"), &gorm.Config{})
require.NoError(t, err)
require.NoError(t, db.AutoMigrate(&models.SSLCertificate{}))
@@ -147,6 +148,8 @@ func TestCertificateHandler_Delete(t *testing.T) {
require.NotZero(t, cert.ID)
service := services.NewCertificateService(tmpDir, db)
// Allow background sync goroutine to complete before testing
time.Sleep(50 * time.Millisecond)
ns := services.NewNotificationService(db)
handler := NewCertificateHandler(service, ns)