You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

testhelper.go 809B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package queue
  4. import (
  5. "fmt"
  6. "sync"
  7. )
  8. // testStateRecorder is used to record state changes for testing, to help debug async behaviors
  9. type testStateRecorder struct {
  10. records []string
  11. mu sync.Mutex
  12. }
  13. var testRecorder = &testStateRecorder{}
  14. func (t *testStateRecorder) Record(format string, args ...any) {
  15. t.mu.Lock()
  16. t.records = append(t.records, fmt.Sprintf(format, args...))
  17. if len(t.records) > 1000 {
  18. t.records = t.records[len(t.records)-1000:]
  19. }
  20. t.mu.Unlock()
  21. }
  22. func (t *testStateRecorder) Records() []string {
  23. t.mu.Lock()
  24. r := make([]string, len(t.records))
  25. copy(r, t.records)
  26. t.mu.Unlock()
  27. return r
  28. }
  29. func (t *testStateRecorder) Reset() {
  30. t.mu.Lock()
  31. t.records = nil
  32. t.mu.Unlock()
  33. }