2020-01-08 19:51:21 +01:00
|
|
|
package mutex
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2022-09-28 09:01:17 +02:00
|
|
|
func TestActivity_Running(t *testing.T) {
|
|
|
|
b := Activity{}
|
2020-01-08 19:51:21 +01:00
|
|
|
|
2022-09-28 09:01:17 +02:00
|
|
|
assert.False(t, b.Running())
|
2020-01-08 19:51:21 +01:00
|
|
|
assert.False(t, b.Canceled())
|
|
|
|
assert.Nil(t, b.Start())
|
2022-09-28 09:01:17 +02:00
|
|
|
assert.True(t, b.Running())
|
2020-01-08 19:51:21 +01:00
|
|
|
assert.False(t, b.Canceled())
|
|
|
|
b.Cancel()
|
|
|
|
assert.True(t, b.Canceled())
|
2022-09-28 09:01:17 +02:00
|
|
|
assert.True(t, b.Running())
|
2020-01-08 19:51:21 +01:00
|
|
|
b.Stop()
|
|
|
|
assert.False(t, b.Canceled())
|
2022-09-28 09:01:17 +02:00
|
|
|
assert.False(t, b.Running())
|
2020-01-08 19:51:21 +01:00
|
|
|
}
|
2020-07-08 13:18:19 +02:00
|
|
|
|
2022-09-28 09:01:17 +02:00
|
|
|
func TestActivity_Start(t *testing.T) {
|
2020-07-08 13:18:19 +02:00
|
|
|
t.Run("cancelled true", func(t *testing.T) {
|
2022-09-28 09:01:17 +02:00
|
|
|
b := Activity{canceled: true}
|
2020-07-08 13:18:19 +02:00
|
|
|
|
|
|
|
assert.Error(t, b.Start(), "still running")
|
|
|
|
})
|
|
|
|
t.Run("busy true", func(t *testing.T) {
|
2022-09-28 09:01:17 +02:00
|
|
|
b := Activity{busy: true}
|
2020-07-08 13:18:19 +02:00
|
|
|
|
|
|
|
assert.Error(t, b.Start(), "already running")
|
|
|
|
})
|
|
|
|
t.Run("success", func(t *testing.T) {
|
2022-09-28 09:01:17 +02:00
|
|
|
b := Activity{}
|
2020-07-08 13:18:19 +02:00
|
|
|
|
|
|
|
assert.Nil(t, b.Start())
|
|
|
|
})
|
|
|
|
}
|