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