forgejo/modules/util/timer_test.go
Gusted 77dbc35138 chore: add modernizer linter (#11936)
- Go has a suite of small linters that helps with modernizing Go code by using newer functions and catching small mistakes, https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/modernize.
- Enable this linter in golangci-lint.
- There's also [`go fix`](https://go.dev/blog/gofix), which is not yet released as a linter in golangci-lint: https://github.com/golangci/golangci-lint/pull/6385

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/11936
Reviewed-by: Mathieu Fenniak <mfenniak@noreply.codeberg.org>
Co-authored-by: Gusted <postmaster@gusted.xyz>
Co-committed-by: Gusted <postmaster@gusted.xyz>
2026-04-02 03:29:37 +02:00

30 lines
668 B
Go

// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package util
import (
"sync/atomic"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestDebounce(t *testing.T) {
var c atomic.Int64
d := Debounce(50 * time.Millisecond)
d(func() { c.Add(1) })
assert.EqualValues(t, 0, c.Load())
d(func() { c.Add(1) })
d(func() { c.Add(1) })
time.Sleep(100 * time.Millisecond)
assert.EqualValues(t, 1, c.Load())
d(func() { c.Add(1) })
assert.EqualValues(t, 1, c.Load())
d(func() { c.Add(1) })
d(func() { c.Add(1) })
d(func() { c.Add(1) })
time.Sleep(100 * time.Millisecond)
assert.EqualValues(t, 2, c.Load())
}