Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sped up tests by 1.5seconds/test #1060

Merged
merged 3 commits into from
Dec 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pkg/controllers/provisioning/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ func (p *Provisioner) batch(ctx context.Context) (pods []*v1.Pod) {
logging.FromContext(ctx).Infof("Batched %d pods in %s", len(pods), time.Since(start))
}()
for {
if len(pods) >= MaxPodsPerBatch {
return pods
}
select {
case pod := <-p.pods:
idle.Reset(MinBatchDuration)
pods = append(pods, pod)
if len(pods) >= MaxPodsPerBatch {
return pods
}
case <-ctx.Done():
return pods
case <-timeout.C:
Expand Down
54 changes: 26 additions & 28 deletions pkg/test/expectations/expectations.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

//nolint:revive,stylecheck
. "github.com/onsi/gomega"

appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/api/policy/v1beta1"
Expand Down Expand Up @@ -110,44 +111,40 @@ func ExpectCreatedWithStatus(ctx context.Context, c client.Client, objects ...cl

func ExpectDeleted(ctx context.Context, c client.Client, objects ...client.Object) {
for _, object := range objects {
persisted := object.DeepCopyObject()
object.SetFinalizers([]string{})
Expect(c.Patch(ctx, object, client.MergeFrom(persisted.(client.Object)))).To(Succeed())
if err := c.Delete(ctx, object, &client.DeleteOptions{GracePeriodSeconds: ptr.Int64(0)}); !errors.IsNotFound(err) {
Expect(err).To(BeNil())
}
}
for _, object := range objects {
ExpectNotFound(ctx, c, object)
}
}

func ExpectCleanedUp(ctx context.Context, c client.Client) {
pdbs := v1beta1.PodDisruptionBudgetList{}
Expect(c.List(ctx, &pdbs)).To(Succeed())
for i := range pdbs.Items {
ExpectDeleted(ctx, c, &pdbs.Items[i])
}
pods := v1.PodList{}
Expect(c.List(ctx, &pods)).To(Succeed())
for i := range pods.Items {
ExpectDeleted(ctx, c, &pods.Items[i])
}
nodes := v1.NodeList{}
Expect(c.List(ctx, &nodes)).To(Succeed())
wg := sync.WaitGroup{}
namespaces := &v1.NamespaceList{}
Expect(c.List(ctx, namespaces)).To(Succeed())
nodes := &v1.NodeList{}
Expect(c.List(ctx, nodes))
for i := range nodes.Items {
ExpectDeleted(ctx, c, &nodes.Items[i])
}
daemonsets := appsv1.DaemonSetList{}
Expect(c.List(ctx, &daemonsets)).To(Succeed())
for i := range daemonsets.Items {
ExpectDeleted(ctx, c, &daemonsets.Items[i])
}
provisioners := v1alpha5.ProvisionerList{}
Expect(c.List(ctx, &provisioners)).To(Succeed())
for i := range provisioners.Items {
ExpectDeleted(ctx, c, &provisioners.Items[i])
nodes.Items[i].SetFinalizers([]string{})
Expect(c.Update(ctx, &nodes.Items[i])).To(Succeed())
}
for _, object := range []client.Object{
&v1.Pod{},
&v1.Node{},
&appsv1.DaemonSet{},
&v1beta1.PodDisruptionBudget{},
&v1.PersistentVolumeClaim{},
&v1alpha5.Provisioner{},
} {
for _, namespace := range namespaces.Items {
wg.Add(1)
go func(object client.Object, namespace string) {
Expect(c.DeleteAllOf(ctx, object, client.InNamespace(namespace))).ToNot(HaveOccurred())
wg.Done()
}(object, namespace.Name)
}
}
wg.Wait()
}

// ExpectProvisioningCleanedUp includes additional cleanup logic for provisioning workflows
Expand All @@ -161,6 +158,7 @@ func ExpectProvisioningCleanedUp(ctx context.Context, c client.Client, controlle
}

func ExpectProvisioned(ctx context.Context, c client.Client, selectionController *selection.Controller, provisioningController *provisioning.Controller, provisioner *v1alpha5.Provisioner, pods ...*v1.Pod) (result []*v1.Pod) {
provisioning.MaxPodsPerBatch = len(pods)
njtran marked this conversation as resolved.
Show resolved Hide resolved
// Persist objects
ExpectApplied(ctx, c, provisioner)
ExpectStatusUpdated(ctx, c, provisioner)
Expand Down