e2e: use Ginkgo context
All code must use the context from Ginkgo when doing API calls or polling for a change, otherwise the code would not return immediately when the test gets aborted.
This commit is contained in:
@@ -139,7 +139,6 @@ func TestMain(m *testing.M) {
|
||||
const rootfs = "/rootfs"
|
||||
|
||||
func TestE2eNode(t *testing.T) {
|
||||
|
||||
// Make sure we are not limited by sshd when it comes to open files
|
||||
if err := rlimit.SetNumFiles(1000000); err != nil {
|
||||
klog.Infof("failed to set rlimit on max file handles: %v", err)
|
||||
@@ -195,7 +194,7 @@ func TestE2eNode(t *testing.T) {
|
||||
}
|
||||
|
||||
// Setup the kubelet on the node
|
||||
var _ = ginkgo.SynchronizedBeforeSuite(func() []byte {
|
||||
var _ = ginkgo.SynchronizedBeforeSuite(func(ctx context.Context) []byte {
|
||||
// Run system validation test.
|
||||
gomega.Expect(validateSystem()).To(gomega.Succeed(), "system validation")
|
||||
|
||||
@@ -203,7 +202,7 @@ var _ = ginkgo.SynchronizedBeforeSuite(func() []byte {
|
||||
// This helps with debugging test flakes since it is hard to tell when a test failure is due to image pulling.
|
||||
if framework.TestContext.PrepullImages {
|
||||
klog.Infof("Pre-pulling images so that they are cached for the tests.")
|
||||
updateImageAllowList()
|
||||
updateImageAllowList(ctx)
|
||||
err := PrePullAllImages()
|
||||
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
|
||||
}
|
||||
@@ -223,7 +222,7 @@ var _ = ginkgo.SynchronizedBeforeSuite(func() []byte {
|
||||
}
|
||||
|
||||
klog.Infof("Wait for the node to be ready")
|
||||
waitForNodeReady()
|
||||
waitForNodeReady(ctx)
|
||||
|
||||
// Reference common test to make the import valid.
|
||||
commontest.CurrentSuite = commontest.NodeE2E
|
||||
@@ -232,10 +231,10 @@ var _ = ginkgo.SynchronizedBeforeSuite(func() []byte {
|
||||
// Since the bearer token is generated randomly at run time,
|
||||
// we need to distribute the bearer token to other processes to make them use the same token.
|
||||
return []byte(framework.TestContext.BearerToken)
|
||||
}, func(token []byte) {
|
||||
}, func(ctx context.Context, token []byte) {
|
||||
framework.TestContext.BearerToken = string(token)
|
||||
// update test context with node configuration.
|
||||
gomega.Expect(updateTestContext()).To(gomega.Succeed(), "update test context with node config.")
|
||||
gomega.Expect(updateTestContext(ctx)).To(gomega.Succeed(), "update test context with node config.")
|
||||
})
|
||||
|
||||
// Tear down the kubelet on the node
|
||||
@@ -280,7 +279,7 @@ func maskLocksmithdOnCoreos() {
|
||||
}
|
||||
}
|
||||
|
||||
func waitForNodeReady() {
|
||||
func waitForNodeReady(ctx context.Context) {
|
||||
const (
|
||||
// nodeReadyTimeout is the time to wait for node to become ready.
|
||||
nodeReadyTimeout = 2 * time.Minute
|
||||
@@ -289,7 +288,7 @@ func waitForNodeReady() {
|
||||
)
|
||||
client, err := getAPIServerClient()
|
||||
framework.ExpectNoError(err, "should be able to get apiserver client.")
|
||||
gomega.Eventually(func() error {
|
||||
gomega.Eventually(ctx, func() error {
|
||||
node, err := getNode(client)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get node: %v", err)
|
||||
@@ -302,9 +301,9 @@ func waitForNodeReady() {
|
||||
}
|
||||
|
||||
// updateTestContext updates the test context with the node name.
|
||||
func updateTestContext() error {
|
||||
func updateTestContext(ctx context.Context) error {
|
||||
setExtraEnvs()
|
||||
updateImageAllowList()
|
||||
updateImageAllowList(ctx)
|
||||
|
||||
client, err := getAPIServerClient()
|
||||
if err != nil {
|
||||
@@ -319,7 +318,7 @@ func updateTestContext() error {
|
||||
// Update test context with current kubelet configuration.
|
||||
// This assumes all tests which dynamically change kubelet configuration
|
||||
// must: 1) run in serial; 2) restore kubelet configuration after test.
|
||||
kubeletCfg, err := getCurrentKubeletConfig()
|
||||
kubeletCfg, err := getCurrentKubeletConfig(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get kubelet configuration: %v", err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user