mirror of https://github.com/coder/coder.git
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:
parent
41f10e7b69
commit
2a73362026
|
@ -2,6 +2,7 @@ package audit
|
|||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"github.com/coder/coder/coderd/database"
|
||||
)
|
||||
|
@ -30,10 +31,13 @@ func NewMock() *MockAuditor {
|
|||
}
|
||||
|
||||
type MockAuditor struct {
|
||||
mutex sync.Mutex
|
||||
AuditLogs []database.AuditLog
|
||||
}
|
||||
|
||||
func (a *MockAuditor) Export(_ context.Context, alog database.AuditLog) error {
|
||||
a.mutex.Lock()
|
||||
defer a.mutex.Unlock()
|
||||
a.AuditLogs = append(a.AuditLogs, alog)
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue