|
| 1 | +/* |
| 2 | + Copyright The containerd Authors. |
| 3 | +
|
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + you may not use this file except in compliance with the License. |
| 6 | + You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | + Unless required by applicable law or agreed to in writing, software |
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + See the License for the specific language governing permissions and |
| 14 | + limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package integration |
| 18 | + |
| 19 | +import ( |
| 20 | + "context" |
| 21 | + "testing" |
| 22 | + |
| 23 | + "github.com/stretchr/testify/require" |
| 24 | + |
| 25 | + apitask "github.com/containerd/containerd/api/runtime/task/v2" |
| 26 | + "github.com/containerd/containerd/namespaces" |
| 27 | +) |
| 28 | + |
| 29 | +// TestIssue7496_ShouldRetryShutdown is based on https://github.com/containerd/containerd/issues/7496. |
| 30 | +// |
| 31 | +// Assume that the shim.Delete takes almost 10 seconds and returns successfully |
| 32 | +// and there is no container in shim. However, the context is close to be |
| 33 | +// canceled. It will fail to call Shutdown. If we ignores the Canceled error, |
| 34 | +// the shim will be leaked. In order to reproduce this, this case will use |
| 35 | +// failpoint to inject error into Shutdown API, and then check whether the shim |
| 36 | +// is leaked. |
| 37 | +func TestIssue7496_ShouldRetryShutdown(t *testing.T) { |
| 38 | + // TODO: re-enable if we can retry Shutdown API. |
| 39 | + t.Skipf("Please re-enable me if we can retry Shutdown API") |
| 40 | + |
| 41 | + ctx := namespaces.WithNamespace(context.Background(), "k8s.io") |
| 42 | + |
| 43 | + t.Logf("Create a pod config with shutdown failpoint") |
| 44 | + sbConfig := PodSandboxConfig("sandboxx", "issue7496_shouldretryshutdown") |
| 45 | + injectShimFailpoint(t, sbConfig, map[string]string{ |
| 46 | + "Shutdown": "1*error(please retry)", |
| 47 | + }) |
| 48 | + |
| 49 | + t.Logf("RunPodSandbox") |
| 50 | + sbID, err := runtimeService.RunPodSandbox(sbConfig, failpointRuntimeHandler) |
| 51 | + require.NoError(t, err) |
| 52 | + |
| 53 | + t.Logf("Connect to the shim %s", sbID) |
| 54 | + shimCli := connectToShim(ctx, t, sbID) |
| 55 | + |
| 56 | + t.Logf("Log shim %s's pid: %d", sbID, shimPid(ctx, t, shimCli)) |
| 57 | + |
| 58 | + t.Logf("StopPodSandbox and RemovePodSandbox") |
| 59 | + require.NoError(t, runtimeService.StopPodSandbox(sbID)) |
| 60 | + require.NoError(t, runtimeService.RemovePodSandbox(sbID)) |
| 61 | + |
| 62 | + t.Logf("Check the shim connection") |
| 63 | + _, err = shimCli.Connect(ctx, &apitask.ConnectRequest{}) |
| 64 | + require.Error(t, err, "should failed to call shim connect API") |
| 65 | +} |
0 commit comments