Skip to content

Commit f4f421a

Browse files
committed
test: fix sync no watch tests
1 parent d399dfc commit f4f421a

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

pkg/devspace/services/sync.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ import (
1212

1313
// StartSyncFromCmd starts a new sync from command
1414
func (serviceClient *client) StartSyncFromCmd(targetOptions targetselector.Options, syncConfig *latest.SyncConfig, interrupt chan error, noWatch, verbose bool) error {
15+
if noWatch && interrupt == nil {
16+
interrupt = make(chan error)
17+
defer close(interrupt)
18+
}
19+
1520
syncDone := make(chan struct{})
1621
options := &synccontroller.Options{
1722
Interrupt: interrupt,

pkg/devspace/services/synccontroller/controller.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,20 @@ func (c *controller) startSync(options *Options, onInitUploadDone chan struct{},
289289
}
290290

291291
log.Info("Waiting for containers to start...")
292-
container, err := targetselector.GlobalTargetSelector.SelectSingleContainer(context.TODO(), c.client, options.TargetOptions, log)
292+
293+
ctx := context.Background()
294+
if options.Interrupt != nil {
295+
var cancel context.CancelFunc
296+
ctx, cancel = context.WithCancel(ctx)
297+
defer cancel()
298+
299+
go func() {
300+
<-options.Interrupt
301+
cancel()
302+
}()
303+
}
304+
305+
container, err := targetselector.GlobalTargetSelector.SelectSingleContainer(ctx, c.client, options.TargetOptions, log)
293306
if err != nil {
294307
return nil, nil, errors.Errorf("Error selecting pod: %v", err)
295308
}

pkg/devspace/services/targetselector/target_selector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ func (t *targetSelector) selectSingle(ctx context.Context, client kubectl.Client
218218
}
219219

220220
var out interface{}
221-
err := wait.PollImmediate(time.Second, timeout, func() (done bool, err error) {
221+
err := wait.PollImmediateWithContext(ctx, time.Second, timeout, func(ctx context.Context) (done bool, err error) {
222222
done, o, err := selectFn(ctx, client, options, log)
223223
if err != nil {
224224
return false, err

0 commit comments

Comments
 (0)