Add graceful shutdown support for async runners (#125)

This commit is contained in:
C Cirello
2016-10-06 00:32:56 +02:00
committed by GitHub
parent 1e62c2a403
commit aa12f3c724
3 changed files with 78 additions and 22 deletions

View File

@@ -7,7 +7,9 @@ import (
"math/rand"
"net/http"
"net/http/httptest"
"sync"
"testing"
"time"
"github.com/Sirupsen/logrus"
"github.com/gin-gonic/gin"
@@ -167,3 +169,21 @@ func TestTasksrvURL(t *testing.T) {
}
}
}
func TestAsyncRunnersGracefulShutdown(t *testing.T) {
mockTask := getMockTask()
ts := getTestServer([]*models.Task{&mockTask})
defer ts.Close()
ctx, _ := context.WithTimeout(context.Background(), 2*time.Second)
var wg sync.WaitGroup
wg.Add(1)
go startAsyncRunners(ctx, &wg, 0, ts.URL+"/tasks", func(task *models.Task) error {
return nil
})
wg.Wait()
if err := ctx.Err(); err != context.DeadlineExceeded {
t.Errorf("async runners stopped unexpectedly. context error: %v", err)
}
}