Skip to content

Commit 10cd657

Browse files
committed
tests: fix sync tests
1 parent 1ad2c15 commit 10cd657

File tree

8 files changed

+56
-14
lines changed

8 files changed

+56
-14
lines changed

cmd/sync.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ func (cmd *SyncCmd) Run(f factory.Factory) error {
123123
}
124124

125125
// Switch working directory
126-
if cmd.GlobalFlags.ConfigPath != "" {
127-
_, err := os.Stat(cmd.GlobalFlags.ConfigPath)
126+
if cmd.ConfigPath != "" {
127+
_, err := os.Stat(cmd.ConfigPath)
128128
if err != nil {
129129
return errors.Errorf("--config is specified, but config %s cannot be loaded: %v", cmd.GlobalFlags.ConfigPath, err)
130130
}
@@ -251,6 +251,8 @@ func (cmd *SyncCmd) Run(f factory.Factory) error {
251251
break
252252
}
253253
}
254+
} else {
255+
syncConfig = syncConfigs[0]
254256
}
255257
}
256258

@@ -272,7 +274,7 @@ func (cmd *SyncCmd) Run(f factory.Factory) error {
272274

273275
// Start sync
274276
options = options.WithSkipInitContainers(true)
275-
return sync.StartSyncFromCmd(ctx, targetselector.NewTargetSelector(options), syncConfig.syncConfig, cmd.NoWatch, cmd.Verbose)
277+
return sync.StartSyncFromCmd(ctx, targetselector.NewTargetSelector(options), syncConfig.devPod.Name, syncConfig.syncConfig, cmd.NoWatch, cmd.Verbose)
276278
}
277279

278280
func fromSyncConfig(devPod *latest.DevPod, containerName string, sc *latest.SyncConfig) (nameConfig, error) {

e2e/tests/dependencies/dependencies.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var _ = DevSpaceDescribe("dependencies", func() {
3838
kubeClient, err = kube.NewKubeHelper()
3939
})
4040

41-
ginkgo.FIt("should skip equal dependencies", func() {
41+
ginkgo.It("should skip equal dependencies", func() {
4242
tempDir, err := framework.CopyToTempDir("tests/dependencies/testdata/overlapping")
4343
framework.ExpectNoError(err)
4444
defer framework.CleanupTempDir(initialDir, tempDir)

e2e/tests/sync/sync.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ var _ = DevSpaceDescribe("sync", func() {
9090
framework.ExpectNoError(err)
9191

9292
// rerun sync command
93+
syncCmd.Ctx = nil
9394
err = syncCmd.Run(f)
9495
framework.ExpectNoError(err)
9596

@@ -482,7 +483,8 @@ var _ = DevSpaceDescribe("sync", func() {
482483
Namespace: ns,
483484
ConfigPath: "devspace.yaml",
484485
},
485-
Ctx: cancelCtx,
486+
Wait: true,
487+
Ctx: cancelCtx,
486488
}
487489

488490
// start the command

pkg/devspace/services/portforwarding/portforwarding.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ func startForwarding(ctx *devspacecontext.Context, name string, portMappings []*
160160
case <-readyChan:
161161
ctx.Log.Donef("Port forwarding started on %s (%s/%s)", strings.Join(ports, ", "), pod.Namespace, pod.Name)
162162
case err := <-errorChan:
163+
if ctx.IsDone() {
164+
return nil
165+
}
166+
163167
return errors.Wrap(err, "forward ports")
164168
case <-time.After(20 * time.Second):
165169
return errors.Errorf("Timeout waiting for port forwarding to start")
@@ -172,6 +176,11 @@ func startForwarding(ctx *devspacecontext.Context, name string, portMappings []*
172176
pf.Close()
173177
stopPortForwarding(ctx, name, portMappings, fileLog, parent)
174178
case err := <-errorChan:
179+
if ctx.IsDone() {
180+
pf.Close()
181+
stopPortForwarding(ctx, name, portMappings, fileLog, parent)
182+
return nil
183+
}
175184
if err != nil {
176185
fileLog.Errorf("Portforwarding restarting, because: %v", err)
177186
sync.PrintPodError(ctx.Context, ctx.KubeClient, pod, fileLog)

pkg/devspace/services/portforwarding/reverse_portforwarding.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ func startReversePortForwarding(ctx *devspacecontext.Context, name, arch string,
6262
_ = stdoutWriter.Close()
6363
doneReverseForwarding(ctx, name, portForwarding, fileLog, parent)
6464
case err := <-errorChan:
65+
if ctx.IsDone() {
66+
close(closeChan)
67+
_ = stdinWriter.Close()
68+
_ = stdoutWriter.Close()
69+
doneReverseForwarding(ctx, name, portForwarding, fileLog, parent)
70+
return nil
71+
}
6572
if err != nil {
6673
fileLog.Errorf("Reverse portforwarding restarting, because: %v", err)
6774
sync.PrintPodError(ctx.Context, ctx.KubeClient, container.Pod, fileLog)

pkg/devspace/services/sync/controller.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ func (c *controller) startWithWait(ctx *devspacecontext.Context, options *Option
132132
if pluginErr != nil {
133133
return pluginErr
134134
}
135+
if ctx.IsDone() {
136+
return nil
137+
}
135138
return errors.Wrap(err, "initial sync")
136139
case <-onInitUploadDone:
137140
uploadDone = true
@@ -176,6 +179,10 @@ func (c *controller) startWithWait(ctx *devspacecontext.Context, options *Option
176179
case <-ctx.Context.Done():
177180
syncStop(ctx, client, options, parent)
178181
case err = <-onError:
182+
if ctx.IsDone() {
183+
syncStop(ctx, client, options, parent)
184+
return nil
185+
}
179186
hook.LogExecuteHooks(ctx.WithLogger(options.SyncLog), map[string]interface{}{
180187
"sync_config": options.SyncConfig,
181188
"ERROR": err,

pkg/devspace/services/sync/sync.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ import (
1212
)
1313

1414
// StartSyncFromCmd starts a new sync from command
15-
func StartSyncFromCmd(ctx *devspacecontext.Context, selector targetselector.TargetSelector, syncConfig *latest.SyncConfig, noWatch, verbose bool) error {
15+
func StartSyncFromCmd(ctx *devspacecontext.Context, selector targetselector.TargetSelector, name string, syncConfig *latest.SyncConfig, noWatch, verbose bool) error {
1616
ctx, parent := ctx.WithNewTomb()
1717
options := &Options{
18+
Name: name,
1819
SyncConfig: syncConfig,
1920
Selector: selector,
2021
RestartOnError: true,
@@ -25,23 +26,35 @@ func StartSyncFromCmd(ctx *devspacecontext.Context, selector targetselector.Targ
2526

2627
// Start the tomb
2728
<-parent.NotifyGo(func() error {
29+
// this is needed as otherwise the context
30+
// is cancelled alongside the tomb
31+
parent.Go(func() error {
32+
<-ctx.Context.Done()
33+
return nil
34+
})
35+
2836
return NewController().Start(ctx, options, parent)
2937
})
3038

3139
// Handle no watch
3240
if noWatch {
33-
parent.Kill(nil)
34-
_ = parent.Wait()
35-
return nil
41+
select {
42+
case <-parent.Dead():
43+
return parent.Err()
44+
default:
45+
parent.Kill(nil)
46+
_ = parent.Wait()
47+
return nil
48+
}
3649
}
3750

3851
// Handle interrupt
3952
select {
53+
case <-parent.Dead():
54+
return parent.Err()
4055
case <-ctx.Context.Done():
4156
_ = parent.Wait()
4257
return nil
43-
case <-parent.Dead():
44-
return parent.Err()
4558
}
4659
}
4760

pkg/devspace/services/terminal/terminal.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,13 @@ fi`,
184184
<-errChan
185185
return nil
186186
case err = <-errChan:
187+
if ctx.IsDone() {
188+
return nil
189+
}
190+
187191
if err != nil {
188192
// check if context is done
189-
if ctx.IsDone() {
190-
return nil
191-
} else if exitError, ok := err.(kubectlExec.CodeExitError); ok {
193+
if exitError, ok := err.(kubectlExec.CodeExitError); ok {
192194
// Expected exit codes are (https://shapeshed.com/unix-exit-codes/):
193195
// 1 - Catchall for general errors
194196
// 2 - Misuse of shell builtins (according to Bash documentation)

0 commit comments

Comments
 (0)