summaryrefslogtreecommitdiffstats
path: root/modules/graceful/releasereopen/releasereopen_test.go
blob: 6ab9f955f63d820b54f7f04659833ddef8a55a40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package releasereopen

import (
	"testing"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
)

type testReleaseReopener struct {
	count int
}

func (t *testReleaseReopener) ReleaseReopen() error {
	t.count++
	return nil
}

func TestManager(t *testing.T) {
	m := NewManager()

	t1 := &testReleaseReopener{}
	t2 := &testReleaseReopener{}
	t3 := &testReleaseReopener{}

	_ = m.Register(t1)
	c2 := m.Register(t2)
	_ = m.Register(t3)

	require.NoError(t, m.ReleaseReopen())
	assert.EqualValues(t, 1, t1.count)
	assert.EqualValues(t, 1, t2.count)
	assert.EqualValues(t, 1, t3.count)

	c2()

	require.NoError(t, m.ReleaseReopen())
	assert.EqualValues(t, 2, t1.count)
	assert.EqualValues(t, 1, t2.count)
	assert.EqualValues(t, 2, t3.count)
}