Skip to content

Commit

Permalink
Test that the exit code of 'odo dev' matches the error returned by th…
Browse files Browse the repository at this point in the history
…e cleanup logic
  • Loading branch information
rm3l committed Jun 21, 2023
1 parent 38439a2 commit ceb4872
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
schemaVersion: 2.1.0
metadata:
name: nodejs
displayName: Node.js Runtime
description: Node.js 16 application
icon: https://nodejs.org/static/images/logos/nodejs-new-pantone-black.svg
tags:
- Node.js
- Express
- ubi8
projectType: Node.js
language: JavaScript
version: 2.1.1
starterProjects:
- name: nodejs-starter
git:
remotes:
origin: 'https://github.com/odo-devfiles/nodejs-ex.git'
attributes:
pod-overrides:
spec:
# This is purposely more than the cleanup timeout (currently set to 1 minute), so that the cleanup does not succeed when the dev session is stopped.
terminationGracePeriodSeconds: 70
components:
- name: runtime
attributes:
container-overrides:
lifecycle:
preStop:
exec:
command: [ "/bin/sh", "-c", "echo pre-stop running forever... && while true; do echo -n . ; sleep 2; done" ]
container:
image: registry.access.redhat.com/ubi8/nodejs-16:latest
args: ['tail', '-f', '/dev/null']
memoryLimit: 1024Mi
mountSources: true
env:
- name: DEBUG_PORT
value: '5858'
endpoints:
- name: http-node
targetPort: 3000
- exposure: none
name: debug
targetPort: 5858
17 changes: 11 additions & 6 deletions tests/helper/helper_dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,18 @@ func (o *DevSession) WaitRestartPortforward() error {
func (o *DevSession) UpdateInfo() error {
outContents := o.session.Out.Contents()
errContents := o.session.Err.Contents()
err := o.session.Out.Clear()
if err != nil {
return err
var err error
if !o.session.Out.Closed() {
err = o.session.Out.Clear()
if err != nil {
return err
}
}
err = o.session.Err.Clear()
if err != nil {
return err
if !o.session.Err.Closed() {
err = o.session.Err.Clear()
if err != nil {
return err
}
}
o.StdOut = string(outContents)
o.ErrOut = string(errContents)
Expand Down
49 changes: 49 additions & 0 deletions tests/integration/cmd_dev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4937,4 +4937,53 @@ CMD ["npm", "start"]
}
}))
}

Context("cleanup of resources is not successful", func() {
for _, podman := range []bool{false, true} {
podman := podman
When("using a Devfile with a Pod failing to delete before the cleanup timeout", helper.LabelPodmanIf(podman, func() {
BeforeEach(func() {
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context)
helper.CopyExampleDevFile(
filepath.Join("source", "devfiles", "nodejs", "devfile-with-container-failing-to-terminate-before-cleanup-timeout.yaml"),
filepath.Join(commonVar.Context, "devfile.yaml"),
cmpName)
})

When("odo dev is executed", helper.LabelPodmanIf(podman, func() {

var devSession helper.DevSession

BeforeEach(func() {
if podman {
Skip("podman does not support container lifecycle hooks and pod termination grace period")
}
var err error
devSession, err = helper.StartDevMode(helper.DevSessionOpts{
RunOnPodman: podman,
})
Expect(err).ToNot(HaveOccurred())
})

When("odo dev is stopped", func() {
BeforeEach(func() {
devSession.Stop()
devSession.WaitEnd()
Expect(devSession.UpdateInfo()).ShouldNot(HaveOccurred())
})

It("should report that the component could not be deleted", func() {
By("deleting the component", func() {
Expect(devSession.ErrOut).Should(ContainSubstring("could not delete the following resource(s)"))
Expect(devSession.ErrOut).Should(ContainSubstring("- Deployment/%s-app", cmpName))
})
By("not exiting successfully", func() {
Expect(devSession.GetExitCode()).ShouldNot(Equal(0), "unexpected exit code for the dev session")
})
})
})
}))
}))
}
})
})

0 comments on commit ceb4872

Please sign in to comment.