Move synctest helper to test package.

This commit is contained in:
Joachim Bauch 2025-12-10 14:42:44 +01:00
commit 8b2cb0fcff
No known key found for this signature in database
GPG key ID: 77C1D22D53E15F02
11 changed files with 66 additions and 15 deletions

View file

@ -42,3 +42,7 @@ component_management:
name: server
paths:
- server/**
- component_id: module_test
name: test
paths:
- test/**

View file

@ -39,4 +39,4 @@ jobs:
run: |
set -euo pipefail
go install golang.org/x/vuln/cmd/govulncheck@latest
govulncheck ./...
GOEXPERIMENT=synctest govulncheck ./...

View file

@ -28,11 +28,13 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/strukturag/nextcloud-spreed-signaling/test"
)
func TestBackoff_Exponential(t *testing.T) {
t.Parallel()
SynctestTest(t, func(t *testing.T) {
test.SynctestTest(t, func(t *testing.T) {
assert := assert.New(t)
minWait := 100 * time.Millisecond
backoff, err := NewExponentialBackoff(minWait, 500*time.Millisecond)

View file

@ -28,6 +28,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/strukturag/nextcloud-spreed-signaling/log"
"github.com/strukturag/nextcloud-spreed-signaling/test"
)
func TestDeferredExecutor_MultiClose(t *testing.T) {
@ -42,7 +43,7 @@ func TestDeferredExecutor_MultiClose(t *testing.T) {
func TestDeferredExecutor_QueueSize(t *testing.T) {
t.Parallel()
SynctestTest(t, func(t *testing.T) {
test.SynctestTest(t, func(t *testing.T) {
logger := log.NewLoggerForTest(t)
e := NewDeferredExecutor(logger, 0)
defer e.waitForStop()

View file

@ -29,6 +29,8 @@ import (
"time"
"github.com/stretchr/testify/assert"
"github.com/strukturag/nextcloud-spreed-signaling/test"
)
func TestNotifierNoWaiter(t *testing.T) {
@ -118,7 +120,7 @@ func TestNotifierResetWillNotify(t *testing.T) {
func TestNotifierDuplicate(t *testing.T) {
t.Parallel()
SynctestTest(t, func(t *testing.T) {
test.SynctestTest(t, func(t *testing.T) {
var notifier Notifier
var done sync.WaitGroup

View file

@ -29,6 +29,8 @@ import (
"time"
"github.com/stretchr/testify/assert"
"github.com/strukturag/nextcloud-spreed-signaling/test"
)
func TestSingleNotifierNoWaiter(t *testing.T) {
@ -118,7 +120,7 @@ func TestSingleNotifierResetWillNotify(t *testing.T) {
func TestSingleNotifierDuplicate(t *testing.T) {
t.Parallel()
SynctestTest(t, func(t *testing.T) {
test.SynctestTest(t, func(t *testing.T) {
var notifier SingleNotifier
var done sync.WaitGroup

View file

@ -21,7 +21,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package signaling
package test
import (
"testing"

View file

@ -21,7 +21,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package signaling
package test
import (
"testing/synctest"

38
test/synctest_test.go Normal file
View file

@ -0,0 +1,38 @@
/**
* Standalone signaling server for the Nextcloud Spreed app.
* Copyright (C) 2025 struktur AG
*
* @author Joachim Bauch <bauch@struktur.de>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package test
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestSynctest(t *testing.T) {
t.Parallel()
SynctestTest(t, func(t *testing.T) {
start := time.Now()
time.Sleep(time.Second)
assert.Equal(t, time.Second, time.Since(start))
})
}

View file

@ -30,6 +30,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/strukturag/nextcloud-spreed-signaling/log"
"github.com/strukturag/nextcloud-spreed-signaling/test"
)
func newMemoryThrottlerForTest(t *testing.T) Throttler {
@ -70,7 +71,7 @@ func expectDelay(t *testing.T, f func(), delay time.Duration) {
func TestThrottler(t *testing.T) {
t.Parallel()
SynctestTest(t, func(t *testing.T) {
test.SynctestTest(t, func(t *testing.T) {
assert := assert.New(t)
th := newMemoryThrottlerForTest(t)
@ -105,7 +106,7 @@ func TestThrottler(t *testing.T) {
func TestThrottlerIPv6(t *testing.T) {
t.Parallel()
SynctestTest(t, func(t *testing.T) {
test.SynctestTest(t, func(t *testing.T) {
assert := assert.New(t)
th := newMemoryThrottlerForTest(t)
@ -143,7 +144,7 @@ func TestThrottlerIPv6(t *testing.T) {
func TestThrottler_Bruteforce(t *testing.T) {
t.Parallel()
SynctestTest(t, func(t *testing.T) {
test.SynctestTest(t, func(t *testing.T) {
assert := assert.New(t)
th := newMemoryThrottlerForTest(t)
@ -170,7 +171,7 @@ func TestThrottler_Bruteforce(t *testing.T) {
func TestThrottler_Cleanup(t *testing.T) {
t.Parallel()
SynctestTest(t, func(t *testing.T) {
test.SynctestTest(t, func(t *testing.T) {
assert := assert.New(t)
throttler := newMemoryThrottlerForTest(t)
th, ok := throttler.(*memoryThrottler)
@ -227,7 +228,7 @@ func TestThrottler_Cleanup(t *testing.T) {
func TestThrottler_ExpirePartial(t *testing.T) {
t.Parallel()
SynctestTest(t, func(t *testing.T) {
test.SynctestTest(t, func(t *testing.T) {
assert := assert.New(t)
th := newMemoryThrottlerForTest(t)
@ -260,7 +261,7 @@ func TestThrottler_ExpirePartial(t *testing.T) {
func TestThrottler_ExpireAll(t *testing.T) {
t.Parallel()
SynctestTest(t, func(t *testing.T) {
test.SynctestTest(t, func(t *testing.T) {
assert := assert.New(t)
th := newMemoryThrottlerForTest(t)
@ -293,7 +294,7 @@ func TestThrottler_ExpireAll(t *testing.T) {
func TestThrottler_Negative(t *testing.T) {
t.Parallel()
SynctestTest(t, func(t *testing.T) {
test.SynctestTest(t, func(t *testing.T) {
assert := assert.New(t)
th := newMemoryThrottlerForTest(t)

View file

@ -33,11 +33,12 @@ import (
"github.com/stretchr/testify/require"
"github.com/strukturag/nextcloud-spreed-signaling/api"
"github.com/strukturag/nextcloud-spreed-signaling/test"
)
func Test_TransientData(t *testing.T) {
t.Parallel()
SynctestTest(t, func(t *testing.T) {
test.SynctestTest(t, func(t *testing.T) {
assert := assert.New(t)
data := NewTransientData()
assert.False(data.Set("foo", nil))