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

test for func run with digested image override #2650

Merged
merged 2 commits into from
Jan 21, 2025

Conversation

gauron99
Copy link
Contributor

add a test for "Func run with digested image when function is already built, expecting to override said built image"

Signed-off-by: David Fridrich <[email protected]>
@knative-prow knative-prow bot requested a review from dsimansk January 15, 2025 09:07
@knative-prow knative-prow bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 15, 2025
@knative-prow knative-prow bot requested a review from vyasgun January 15, 2025 09:07
@knative-prow knative-prow bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jan 15, 2025
@gauron99 gauron99 requested review from matejvasek and lkingland and removed request for dsimansk and vyasgun January 15, 2025 09:08
@gauron99 gauron99 changed the title test for func run with digested image test for func run with digested image override Jan 15, 2025
Copy link

codecov bot commented Jan 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 65.42%. Comparing base (cd59f97) to head (c7bc871).
Report is 13 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2650      +/-   ##
==========================================
+ Coverage   64.13%   65.42%   +1.28%     
==========================================
  Files         130      130              
  Lines       15518    15518              
==========================================
+ Hits         9953    10152     +199     
+ Misses       4625     4389     -236     
- Partials      940      977      +37     
Flag Coverage Δ
e2e-test 35.85% <ø> (ø)
e2e-test-oncluster 32.90% <ø> (ø)
e2e-test-oncluster-runtime 28.65% <ø> (?)
e2e-test-runtime-go 26.44% <ø> (?)
e2e-test-runtime-node 25.84% <ø> (?)
e2e-test-runtime-python 25.84% <ø> (?)
e2e-test-runtime-quarkus 25.96% <ø> (?)
e2e-test-runtime-rust 24.92% <ø> (?)
e2e-test-runtime-springboot 24.98% <ø> (?)
e2e-test-runtime-typescript 25.95% <ø> (?)
integration-tests 51.97% <ø> (+2.30%) ⬆️
unit-tests 50.95% <ø> (?)
unit-tests-macos-latest ?
unit-tests-ubuntu-latest ?
unit-tests-windows-latest ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: David Fridrich <[email protected]>
ctx, cancel := context.WithCancel(context.Background())
runErrCh := make(chan error, 1)
go func() {
_, err := cmd.ExecuteContextC(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

This probably could be just err := cmd.ExecuteContext(ctx)

// run function with above argument
ctx, cancel := context.WithCancel(context.Background())
runErrCh := make(chan error, 1)
go func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we could get rid of this asynchronicity by closing err channel in the runner:

diff --git a/cmd/run_test.go b/cmd/run_test.go
index 7340ca59f..88130ea83 100644
--- a/cmd/run_test.go
+++ b/cmd/run_test.go
@@ -398,7 +398,8 @@ func TestRun_DirectOverride(t *testing.T) {
 		if f.Build.Image != overrideImage {
 			return nil, fmt.Errorf("Expected image to be overridden with '%v' but got: '%v'", overrideImage, f.Build.Image)
 		}
-		errs := make(chan error, 1)
+		errs := make(chan error)
+		close(errs)
 		stop := func() error { return nil }
 		return fn.NewJob(f, "127.0.0.1", "8080", errs, stop, false)
 	}
@@ -440,25 +441,16 @@ func TestRun_DirectOverride(t *testing.T) {
 
 	// run function with above argument
 	ctx, cancel := context.WithCancel(context.Background())
-	runErrCh := make(chan error, 1)
-	go func() {
-		_, err := cmd.ExecuteContextC(ctx)
+	defer cancel()
+
+	err = cmd.ExecuteContext(ctx)
 	if err != nil {
-			runErrCh <- err // error was not expected
-			return
+		t.Fatal(err)
 	}
 
 	// Ensure invocation doesnt happen for the second time as the image was
 	// provided with a digest (should not build)
 	if builder2.BuildInvoked {
-			runErrCh <- fmt.Errorf("Function was not expected to build again but it did")
-		}
-
-		close(runErrCh) // release the waiting parent process
-	}()
-	cancel() // trigger the return of cmd.ExecuteContextC in the routine
-	<-ctx.Done()
-	if err := <-runErrCh; err != nil { // wait for completion of assertions
-		t.Fatal(err)
+		t.Fatal("Function was not expected to build again but it did")
 	}
 }

@matejvasek
Copy link
Contributor

Some nits, but otherwise looks good.

@matejvasek
Copy link
Contributor

/approve
/lgtm

@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label Jan 21, 2025
Copy link

knative-prow bot commented Jan 21, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gauron99, matejvasek

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

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [gauron99,matejvasek]

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

@knative-prow knative-prow bot merged commit 020dd96 into knative:main Jan 21, 2025
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants