Skip to content

Commit

Permalink
e2e: cleanup when test is cancelled
Browse files Browse the repository at this point in the history
  • Loading branch information
davidweisse committed Jun 17, 2024
1 parent 131b5d8 commit cdec5e0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/e2e_openssl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
permissions:
contents: read
packages: write
env:
SKIP_UNDEPLOY: ${{ inputs.skip-undeploy }}
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: ./.github/actions/setup_nix
Expand Down Expand Up @@ -61,3 +63,7 @@ jobs:
- name: E2E Test
run: |
nix shell .#contrast.e2e --command openssl.test -test.v workspace/just.containerlookup
- name: Cleanup
if: cancelled() && inputs.skip-undeploy != 'true'
run: |
kubectl delete ns $(cat e2e.namespace) --timeout 5m
8 changes: 5 additions & 3 deletions .github/workflows/e2e_servicemesh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
permissions:
contents: read
packages: write
env:
SKIP_UNDEPLOY: ${{ inputs.skip-undeploy }}
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: ./.github/actions/setup_nix
Expand Down Expand Up @@ -61,7 +63,7 @@ jobs:
- name: E2E Test
run: |
nix shell .#contrast.e2e --command servicemesh.test -test.v workspace/just.containerlookup
- name: Undeploy
if: always() && inputs.skip-undeploy != 'true'
- name: Cleanup
if: cancelled() && inputs.skip-undeploy != 'true'
run: |
just undeploy
kubectl delete ns $(cat e2e.namespace) --timeout 5m
13 changes: 8 additions & 5 deletions e2e/internal/contrasttest/contrasttest.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,22 @@ func (ct *ContrastTest) Init(t *testing.T, resources []any) {
// Create namespace
namespace, err := kuberesource.ResourcesToUnstructured([]any{kuberesource.Namespace(ct.Namespace)})
require.NoError(err)
require.NoError(os.WriteFile(path.Join(ct.WorkDir, "e2e.namespace"), []byte(ct.Namespace), 0o644))
// Creating a namespace should not take too long.
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
err = ct.Kubeclient.Apply(ctx, namespace...)
cancel()
require.NoError(err)

t.Cleanup(func() {
// Deleting the namespace may take some time due to pod cleanup, but we don't want to wait until the test times out.
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()
if os.Getenv("SKIP_UNDEPLOY") != "true" {
// Deleting the namespace may take some time due to pod cleanup, but we don't want to wait until the test times out.
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()

if err := ct.Kubeclient.Delete(ctx, namespace...); err != nil {
t.Logf("Could not delete namespace %q: %v", ct.Namespace, err)
if err := ct.Kubeclient.Delete(ctx, namespace...); err != nil {
t.Logf("Could not delete namespace %q: %v", ct.Namespace, err)
}
}

if fifo != nil {
Expand Down

0 comments on commit cdec5e0

Please sign in to comment.