mirror of
https://github.com/coder/coder.git
synced 2025-07-08 11:39:50 +00:00
fix: add mutex to MockAuditor export to prevent race (#5189)
See: https://github.com/coder/coder/actions/runs/3575201153/jobs/6011435900.
This commit is contained in:
@ -2,6 +2,7 @@ package audit
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/coder/coder/coderd/database"
|
"github.com/coder/coder/coderd/database"
|
||||||
)
|
)
|
||||||
@ -30,10 +31,13 @@ func NewMock() *MockAuditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type MockAuditor struct {
|
type MockAuditor struct {
|
||||||
|
mutex sync.Mutex
|
||||||
AuditLogs []database.AuditLog
|
AuditLogs []database.AuditLog
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *MockAuditor) Export(_ context.Context, alog database.AuditLog) error {
|
func (a *MockAuditor) Export(_ context.Context, alog database.AuditLog) error {
|
||||||
|
a.mutex.Lock()
|
||||||
|
defer a.mutex.Unlock()
|
||||||
a.AuditLogs = append(a.AuditLogs, alog)
|
a.AuditLogs = append(a.AuditLogs, alog)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user