-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The reconcile tests were causing panics or tripping race detection because the timeout handler was using the *testing.T methods after the test was already marked done. The solution is to use loggers that are not tied to the testing framework. The downside is that you may see logs from prior tests intermixed but that is usually just the one associated with stopping the timeout.
- Loading branch information
Showing
9 changed files
with
55 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package testing | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"go.uber.org/zap" | ||
"knative.dev/pkg/controller" | ||
"knative.dev/pkg/logging" | ||
rtesting "knative.dev/pkg/reconciler/testing" | ||
) | ||
|
||
func SetupFakeContext(t *testing.T) (context.Context, []controller.Informer) { | ||
ctx, informer := rtesting.SetupFakeContext(t) | ||
return WithLogger(ctx, t), informer | ||
} | ||
|
||
func WithLogger(ctx context.Context, t *testing.T) context.Context { | ||
return logging.WithLogger(ctx, TestLogger(t)) | ||
} | ||
|
||
func TestLogger(t *testing.T) *zap.SugaredLogger { | ||
logger, err := zap.NewDevelopment(zap.AddCaller()) | ||
if err != nil { | ||
t.Fatalf("failed to create logger: %s", err) | ||
} | ||
return logger.Sugar().Named(t.Name()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters