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

Proposal: New coding standards for properly use contexts in functional tests #304

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nunnatsa
Copy link
Contributor

Release note:

New coding standards for properly use contexts in functional tests

@kubevirt-bot kubevirt-bot added the dco-signoff: yes Indicates the PR's author has DCO signed all their commits. label Jun 19, 2024
@kubevirt-bot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign cwilkers for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@nunnatsa
Copy link
Contributor Author

/cc @0xFelix
/cc @fossedihelm
/cc @jean-edouard
/cc @EdDev

@fabiand
Copy link
Member

fabiand commented Jun 19, 2024

👋

How does this relate to the work that Felix did in kubevirt/kubevirt repo.
Why do we have some parts here and some parts there?
How will we ensure that developers know where to look?


## Goals
- Define coding standards for the functional tests, regarding the proper way of using contexts
- Modify the current code to use the new standards
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By code you mean test code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. I can fix that. but I think the context of this whole page is about functional tests.

Comment on lines 15 to 16
Closing this gap is a huge effort. Contexts should be passed deeper and deeper down
the call stack, changing the api of many functions and methods. The impact is meaningful.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we talking about the actual code or the test code here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In which way is the impact meaningful? Measurable time difference? Less hangs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I was trying to say is that in production code, it will be very hard to move contexts around, and it much easier to do that in the functional tests, so let's start there

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-wrote the whole paragraph.

in golang, when writing an asynchronous logic. In a way, the KubeVirt code left
behind regarding the proper usage of golang contexts.

Using `context.Background()` or even worse, `context.TODO()` is a code smell, because
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could not just be the termination of the application but also termination of a goroutine.

- Using the new standards as a gate for code review of functional tests

## Design
### Coding Standards for Using contexts in Functional Tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### Coding Standards for Using contexts in Functional Tests
### Coding Standards for using contexts in Functional Tests

### Coding Standards for Using contexts in Functional Tests

To make sure that any asynchronous operation is canceled when a test is
terminated, make sure to use golang contexts properly. See more details in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what using a context properly means? IIUC we are not using the appropriate contexts provided by Ginkgo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not using ginkgo contexts at all. We're using mostly context.Background() and sometimes context.TODO()

@nunnatsa
Copy link
Contributor Author

👋

How does this relate to the work that Felix did in kubevirt/kubevirt repo. Why do we have some parts here and some parts there? How will we ensure that developers know where to look?

Not sure I'm familiar with the work Felix did. The suggestion is to add the coding standards to the kubevirt/kubevirt repo.

My PR was merged but is about to be reverted, because there was no proper discussion about it: kubevirt/kubevirt#12148

Comment on lines +39 to +40
Avoid using new contexts (e.g. `context.Background()` or `context.TODO()`).
Instead, prefer using the context injected by ginkgo.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop this paragraph, it duplicates what was already said above.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Contributor

@jean-edouard jean-edouard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes so much sense to me, not quite sure why it's so controversial...
@0xFelix do you still have any unresolved concern?
@fossedihelm any objection to me approving this?

# Properly use contexts in functional tests

## Overview
This proposal is about properly use golang contexts in KubeVirt functional tests.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This proposal is about properly use golang contexts in KubeVirt functional tests.
This proposal is about properly using golang contexts in KubeVirt functional tests.


## Introduction
Since the start of the KubeVirt project, contexts became a very important concept
in golang, when writing an asynchronous logic. In a way, the KubeVirt code left
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
in golang, when writing an asynchronous logic. In a way, the KubeVirt code left
in golang, when writing an asynchronous logic. In a way, the KubeVirt code is left

?

@EdDev
Copy link
Member

EdDev commented Sep 28, 2024

This makes so much sense to me, not quite sure why it's so controversial…

It is controversial because in the current form of the tests, it will make them harder to read and add a lot of boilerplate code.
AFAIK it mainly got stuck due to priority. There are other issues to handle in our codebase which have precedence.

We will also need all SIGs approval to enforce this. I’m unsure if all will be able to commit following this.

details:
[https://onsi.github.io/ginkgo/#spec-timeouts-and-interruptible-nodes](https://onsi.github.io/ginkgo/#spec-timeouts-and-interruptible-nodes)

## Goals
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I am missing the outcomes.

Copy link
Member

@0xFelix 0xFelix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not much to add, other than two comments and +1 to @xpivarc's comment.

The test code should use the contexts provided by ginkgo, rather than new contexts
like `context.Background()` or `context.TODO()`.

The following guidelines are base on the [ginkgo documentation](https://onsi.github.io/ginkgo/#spec-timeouts-and-interruptible-nodes).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The following guidelines are base on the [ginkgo documentation](https://onsi.github.io/ginkgo/#spec-timeouts-and-interruptible-nodes).
The following guidelines are based on the [ginkgo documentation](https://onsi.github.io/ginkgo/#spec-timeouts-and-interruptible-nodes).

Comment on lines +39 to +40
Avoid using new contexts (e.g. `context.Background()` or `context.TODO()`).
Instead, prefer using the context injected by ginkgo.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dco-signoff: yes Indicates the PR's author has DCO signed all their commits. size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants