Skip to content

Commit

Permalink
daemon: fix flaky test
Browse files Browse the repository at this point in the history
Signed-off-by: Denys Smirnov <[email protected]>
  • Loading branch information
Denys Smirnov authored and dennwc committed Apr 10, 2019
1 parent 62a6b0d commit 9a9c8bf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 7 additions & 0 deletions daemon/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,13 @@ func (dp *DriverPool) manageDrivers() {
// pool scaling limit. The caller should put the instance back to the pool even if the
// driver fails.
func (dp *DriverPool) getIdle(rctx context.Context) (Driver, error) {
// don't do anything if the request is already cancelled,
// or we will have to "rollback" it later
select {
case <-rctx.Done():
return nil, rctx.Err()
default:
}
// fast path - get an idle driver directly from the pool
// this function executes on the current goroutine
if d, ok := dp.peekIdle(); ok {
Expand Down
9 changes: 7 additions & 2 deletions daemon/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package daemon

import (
"context"
"errors"
"fmt"
"runtime"
"sync"
Expand All @@ -28,7 +29,9 @@ func TestDriverPoolClose_StartNoopClose(t *testing.T) {
err = dp.Stop()
require.True(ErrPoolClosed.Is(err), "%v", err)

err = dp.ExecuteCtx(ctx, nil)
err = dp.ExecuteCtx(ctx, func(ctx context.Context, d Driver) error {
return errors.New("should not happen")
})
require.True(ErrPoolClosed.Is(err), "%v", err)
}

Expand Down Expand Up @@ -65,7 +68,9 @@ func TestDriverPoolExecute_Timeout(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Nanosecond)
defer cancel()

err = dp.ExecuteCtx(ctx, nil)
err = dp.ExecuteCtx(ctx, func(ctx context.Context, d Driver) error {
return errors.New("should not happen")
})
require.True(err == context.DeadlineExceeded)
}

Expand Down

0 comments on commit 9a9c8bf

Please sign in to comment.