(t *testing.T)
| 156 | } |
| 157 | |
| 158 | func TestBaseStartStopFunc(t *testing.T) { |
| 159 | t.Parallel() |
| 160 | |
| 161 | makeFunc := func(t *testing.T) serviceWithStopped { |
| 162 | t.Helper() |
| 163 | |
| 164 | // Some simple state in the service which a started service taints. The |
| 165 | // purpose of this variable is to allow us to detect a data race allowed by |
| 166 | // BaseStartStop. |
| 167 | var state bool |
| 168 | |
| 169 | return StartStopFunc(func(ctx context.Context, shouldStart bool, started, stopped func()) error { |
| 170 | if !shouldStart { |
| 171 | return nil |
| 172 | } |
| 173 | |
| 174 | go func() { |
| 175 | started() |
| 176 | defer stopped() |
| 177 | state = true |
| 178 | t.Logf("State: %t", state) // here so variable doesn't register as unused |
| 179 | <-ctx.Done() |
| 180 | }() |
| 181 | |
| 182 | return nil |
| 183 | }) |
| 184 | } |
| 185 | |
| 186 | testService(t, makeFunc) |
| 187 | } |
| 188 | |
| 189 | func TestErrStop(t *testing.T) { |
| 190 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…