-
Notifications
You must be signed in to change notification settings - Fork 418
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #529 from FabianKramm/main
user shell, inactivity timeout & web timeout
- Loading branch information
Showing
29 changed files
with
525 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package machineprovider | ||
|
||
import "github.com/onsi/ginkgo/v2" | ||
|
||
// DevPodDescribe annotates the test with the label. | ||
func DevPodDescribe(text string, body func()) bool { | ||
return ginkgo.Describe("[machineprovider] "+text, body) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
package machineprovider | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"time" | ||
|
||
"github.com/loft-sh/devpod/e2e/framework" | ||
"github.com/onsi/ginkgo/v2" | ||
) | ||
|
||
var _ = DevPodDescribe("devpod machine provider test suite", func() { | ||
var initialDir string | ||
|
||
ginkgo.BeforeEach(func() { | ||
var err error | ||
initialDir, err = os.Getwd() | ||
framework.ExpectNoError(err) | ||
}) | ||
|
||
ginkgo.It("test start / stop / status", func(ctx context.Context) { | ||
f := framework.NewDefaultFramework(initialDir + "/bin") | ||
|
||
// copy test dir | ||
tempDir, err := framework.CopyToTempDirWithoutChdir(initialDir + "/tests/machineprovider/testdata/machineprovider") | ||
framework.ExpectNoError(err) | ||
ginkgo.DeferCleanup(func() { | ||
_ = os.RemoveAll(tempDir) | ||
}) | ||
|
||
tempDirLocation, err := os.MkdirTemp("", "") | ||
framework.ExpectNoError(err) | ||
ginkgo.DeferCleanup(func() { | ||
_ = os.RemoveAll(tempDirLocation) | ||
}) | ||
|
||
// create docker provider | ||
err = f.DevPodProviderAdd(ctx, filepath.Join(tempDir, "provider.yaml"), "-o", "LOCATION="+tempDirLocation) | ||
framework.ExpectNoError(err) | ||
ginkgo.DeferCleanup(func() { | ||
err = f.DevPodProviderDelete(context.Background(), "docker123") | ||
framework.ExpectNoError(err) | ||
}) | ||
|
||
// wait for devpod workspace to come online (deadline: 30s) | ||
err = f.DevPodUp(ctx, tempDir, "--debug") | ||
framework.ExpectNoError(err) | ||
|
||
// expect workspace | ||
workspace, err := f.FindWorkspace(ctx, tempDir) | ||
framework.ExpectNoError(err) | ||
|
||
// check status | ||
status, err := f.DevPodStatus(ctx, tempDir) | ||
framework.ExpectNoError(err) | ||
framework.ExpectEqual(strings.ToUpper(status.State), "RUNNING", "workspace status did not match") | ||
|
||
// stop container | ||
err = f.DevPodStop(ctx, tempDir) | ||
framework.ExpectNoError(err) | ||
|
||
// check status | ||
status, err = f.DevPodStatus(ctx, tempDir) | ||
framework.ExpectNoError(err) | ||
framework.ExpectEqual(strings.ToUpper(status.State), "STOPPED", "workspace status did not match") | ||
|
||
// wait for devpod workspace to come online (deadline: 30s) | ||
err = f.DevPodUp(ctx, tempDir) | ||
framework.ExpectNoError(err) | ||
|
||
// check if ssh works as it should start the container | ||
out, err := f.DevPodSSH(ctx, tempDir, fmt.Sprintf("cat /workspaces/%s/test.txt", workspace.ID)) | ||
framework.ExpectNoError(err) | ||
framework.ExpectEqual(out, "Test123", "workspace content does not match") | ||
|
||
// delete workspace | ||
err = f.DevPodWorkspaceDelete(ctx, tempDir) | ||
framework.ExpectNoError(err) | ||
}, ginkgo.SpecTimeout(60*time.Second)) | ||
|
||
ginkgo.It("test devpod inactivity timeout", func(ctx context.Context) { | ||
f := framework.NewDefaultFramework(initialDir + "/bin") | ||
|
||
// copy test dir | ||
tempDir, err := framework.CopyToTempDirWithoutChdir(initialDir + "/tests/machineprovider/testdata/machineprovider2") | ||
framework.ExpectNoError(err) | ||
ginkgo.DeferCleanup(func() { | ||
err = os.RemoveAll(tempDir) | ||
framework.ExpectNoError(err) | ||
}) | ||
|
||
tempDirLocation, err := os.MkdirTemp("", "") | ||
framework.ExpectNoError(err) | ||
ginkgo.DeferCleanup(func() { | ||
err = os.RemoveAll(tempDirLocation) | ||
framework.ExpectNoError(err) | ||
}) | ||
|
||
// create provider | ||
_ = f.DevPodProviderDelete(ctx, "docker123") | ||
err = f.DevPodProviderAdd(ctx, filepath.Join(tempDir, "provider.yaml")) | ||
framework.ExpectNoError(err) | ||
ginkgo.DeferCleanup(func() { | ||
err = f.DevPodProviderDelete(context.Background(), "docker123") | ||
framework.ExpectNoError(err) | ||
}) | ||
|
||
// wait for devpod workspace to come online (deadline: 30s) | ||
err = f.DevPodUp(ctx, tempDir, "--debug", "--daemon-interval=3s") | ||
framework.ExpectNoError(err) | ||
ginkgo.DeferCleanup(func() { | ||
// delete workspace | ||
err = f.DevPodWorkspaceDelete(context.Background(), tempDir) | ||
framework.ExpectNoError(err) | ||
}) | ||
|
||
// check status | ||
status, err := f.DevPodStatus(ctx, tempDir, "--container-status=false") | ||
framework.ExpectNoError(err) | ||
framework.ExpectEqual(strings.ToUpper(status.State), "RUNNING", "workspace status did not match") | ||
|
||
// stop container | ||
err = f.DevPodStop(ctx, tempDir) | ||
framework.ExpectNoError(err) | ||
|
||
// check status | ||
status, err = f.DevPodStatus(ctx, tempDir, "--container-status=false") | ||
framework.ExpectNoError(err) | ||
framework.ExpectEqual(strings.ToUpper(status.State), "STOPPED", "workspace status did not match") | ||
|
||
// wait for devpod workspace to come online (deadline: 30s) | ||
err = f.DevPodUp(ctx, tempDir, "--daemon-interval=3s") | ||
framework.ExpectNoError(err) | ||
|
||
// check status | ||
status, err = f.DevPodStatus(ctx, tempDir, "--container-status=false") | ||
framework.ExpectNoError(err) | ||
framework.ExpectEqual(strings.ToUpper(status.State), "RUNNING", "workspace status did not match") | ||
|
||
// wait until workspace is stopped again | ||
now := time.Now() | ||
for { | ||
status, err := f.DevPodStatus(ctx, tempDir, "--container-status=false") | ||
framework.ExpectNoError(err) | ||
framework.ExpectEqual(time.Since(now) < time.Minute*2, true, "machine did not shutdown in time") | ||
if status.State == "Stopped" { | ||
break | ||
} | ||
|
||
time.Sleep(time.Second * 2) | ||
} | ||
}, ginkgo.SpecTimeout(300*time.Second)) | ||
}) |
4 changes: 4 additions & 0 deletions
4
e2e/tests/machineprovider/testdata/machineprovider/.devcontainer.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "Go", | ||
"image": "mcr.microsoft.com/devcontainers/go:0-1.19-bullseye" | ||
} |
30 changes: 30 additions & 0 deletions
30
e2e/tests/machineprovider/testdata/machineprovider/provider.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: docker123 | ||
version: v0.0.1 | ||
description: |- | ||
DevPod on Docker | ||
options: | ||
LOCATION: | ||
description: The location DevPod should use | ||
agent: | ||
local: true | ||
docker: | ||
install: false | ||
exec: | ||
create: |- | ||
mkdir -p ${LOCATION}/${MACHINE_ID} | ||
echo "RUNNING" > ${LOCATION}/${MACHINE_ID}/status.txt | ||
delete: |- | ||
rm -R ${LOCATION}/${MACHINE_ID} | ||
start: |- | ||
echo "RUNNING" > ${LOCATION}/${MACHINE_ID}/status.txt | ||
stop: |- | ||
echo "STOPPED" > ${LOCATION}/${MACHINE_ID}/status.txt | ||
status: |- | ||
cat ${LOCATION}/${MACHINE_ID}/status.txt 2>/dev/null || echo "NOTFOUND" | ||
command: |- | ||
"${DEVPOD}" helper sh -c "${COMMAND}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Test123 |
4 changes: 4 additions & 0 deletions
4
e2e/tests/machineprovider/testdata/machineprovider2/.devcontainer.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "Go", | ||
"image": "ubuntu" | ||
} |
Oops, something went wrong.