diff options
author | Rowan Bohde <rowan.bohde@gmail.com> | 2024-11-14 13:28:46 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-14 19:28:46 +0000 |
commit | 68731c07c52d35b7b44db1c2f5f7a755efcc8c84 (patch) | |
tree | 5357aca5db9027ec978f561c65a496810cb72517 /modules/queue/workerqueue.go | |
parent | 249e67672aea8a5a0ed73bedc655f9dcd37437ea (diff) | |
download | gitea-68731c07c52d35b7b44db1c2f5f7a755efcc8c84.tar.gz gitea-68731c07c52d35b7b44db1c2f5f7a755efcc8c84.zip |
Reduce integration test overhead (#32475)
In profiling integration tests, I found a couple places where per-test
overhead could be reduced:
* Avoiding disk IO by synchronizing instead of deleting & copying test
Git repository data. This saves ~100ms per test on my machine
* When flushing queues in `PrintCurrentTest`, invoke `FlushWithContext`
in a parallel.
---------
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'modules/queue/workerqueue.go')
-rw-r--r-- | modules/queue/workerqueue.go | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/modules/queue/workerqueue.go b/modules/queue/workerqueue.go index b28fd88027..f35ed93239 100644 --- a/modules/queue/workerqueue.go +++ b/modules/queue/workerqueue.go @@ -42,7 +42,10 @@ type WorkerPoolQueue[T any] struct { workerNumMu sync.Mutex } -type flushType chan struct{} +type flushType struct { + timeout time.Duration + c chan struct{} +} var _ ManagedWorkerPoolQueue = (*WorkerPoolQueue[any])(nil) @@ -104,12 +107,12 @@ func (q *WorkerPoolQueue[T]) FlushWithContext(ctx context.Context, timeout time. if timeout > 0 { after = time.After(timeout) } - c := make(flushType) + flush := flushType{timeout: timeout, c: make(chan struct{})} // send flush request // if it blocks, it means that there is a flush in progress or the queue hasn't been started yet select { - case q.flushChan <- c: + case q.flushChan <- flush: case <-ctx.Done(): return ctx.Err() case <-q.ctxRun.Done(): @@ -120,7 +123,7 @@ func (q *WorkerPoolQueue[T]) FlushWithContext(ctx context.Context, timeout time. // wait for flush to finish select { - case <-c: + case <-flush.c: return nil case <-ctx.Done(): return ctx.Err() |