fn: GoroutineManager.Go returns bool, not error

This was requested in https://github.com/lightningnetwork/lnd/pull/9140#discussion_r1821181787
This commit is contained in:
Boris Nagaev committed 2024-11-14 15:03:25 -03:00
1 parent 669ebf49d4
commit 891e9621d7
2 files changed
+15 -17

No files matched your search

+8 -8
View File
@@ -20,7 +20,7 @@ func TestGoroutineManager(t *testing.T) {
taskChan := make(chan struct{})
require.NoError(t, m.Go(func(ctx context.Context) {
require.True(t, m.Go(func(ctx context.Context) {
<-taskChan
}))
@@ -38,7 +38,7 @@ func TestGoroutineManager(t *testing.T) {
require.Greater(t, stopDelay, time.Second)
// Make sure new goroutines do not start after Stop.
require.ErrorIs(t, m.Go(func(ctx context.Context) {}), ErrStopping)
require.False(t, m.Go(func(ctx context.Context) {}))
// When Stop() is called, the internal context expires and m.Done() is
// closed. Test this.
@@ -57,7 +57,7 @@ func TestGoroutineManagerContextExpires(t *testing.T) {
m := NewGoroutineManager(ctx)
require.NoError(t, m.Go(func(ctx context.Context) {
require.True(t, m.Go(func(ctx context.Context) {
<-ctx.Done()
}))
@@ -80,7 +80,7 @@ func TestGoroutineManagerContextExpires(t *testing.T) {
}
// Make sure new goroutines do not start after context expiry.
require.ErrorIs(t, m.Go(func(ctx context.Context) {}), ErrStopping)
require.False(t, m.Go(func(ctx context.Context) {}))
// Stop will wait for all goroutines to stop.
m.Stop()
@@ -108,11 +108,11 @@ func TestGoroutineManagerStress(t *testing.T) {
// implementation, this test crashes under `-race`.
for i := 0; i < 100; i++ {
taskChan := make(chan struct{})
err := m.Go(func(ctx context.Context) {
ok := m.Go(func(ctx context.Context) {
close(taskChan)
})
// If goroutine was started, wait for its completion.
if err == nil {
if ok {
<-taskChan
}
}
@@ -134,10 +134,10 @@ func TestGoroutineManagerStopsStress(t *testing.T) {
jobChan := make(chan struct{})
// Start a task and wait inside it until we start calling Stop() method.
err := m.Go(func(ctx context.Context) {
ok := m.Go(func(ctx context.Context) {
<-jobChan
})
require.NoError(t, err)
require.True(t, ok)
// Now launch many gorotines calling Stop() method in parallel.
var wg sync.WaitGroup