test: use cancelation from ktesting

The return type of ktesting.NewTestContext is now a TContext. Code
which combined it WithCancel often didn't compile anymore (cannot overwrite
ktesting.TContext with context.Context). This is a good thing because all of
that code can be simplified to let ktesting handle the cancelation.
This commit is contained in:
Patrick Ohly
2023-12-25 19:40:56 +01:00
parent 3df07e446b
commit 1d653e6185
34 changed files with 458 additions and 695 deletions

View File

@@ -145,11 +145,8 @@ func (d *noxuDelayingAuthorizer) Authorize(ctx context.Context, a authorizer.Att
// Secondarily, this test also checks the observed seat utilizations against values derived from expecting that
// the throughput observed by the client equals the execution throughput observed by the server.
func TestConcurrencyIsolation(t *testing.T) {
_, ctx := ktesting.NewTestContext(t)
ctx, cancel := context.WithCancel(ctx)
defer cancel()
_, kubeConfig, closeFn := framework.StartTestServer(ctx, t, framework.TestServerSetup{
tCtx := ktesting.Init(t)
_, kubeConfig, closeFn := framework.StartTestServer(tCtx, t, framework.TestServerSetup{
ModifyServerRunOptions: func(opts *options.ServerRunOptions) {
// Ensure all clients are allowed to send requests.
opts.Authorization.Modes = []string{"AlwaysAllow"}
@@ -190,7 +187,7 @@ func TestConcurrencyIsolation(t *testing.T) {
wg.Add(noxu1NumGoroutines)
streamRequests(noxu1NumGoroutines, func() {
start := time.Now()
_, err := noxu1Client.CoreV1().Namespaces().Get(ctx, "default", metav1.GetOptions{})
_, err := noxu1Client.CoreV1().Namespaces().Get(tCtx, "default", metav1.GetOptions{})
duration := time.Since(start).Seconds()
noxu1LatMeasure.update(duration)
if err != nil {
@@ -203,7 +200,7 @@ func TestConcurrencyIsolation(t *testing.T) {
wg.Add(noxu2NumGoroutines)
streamRequests(noxu2NumGoroutines, func() {
start := time.Now()
_, err := noxu2Client.CoreV1().Namespaces().Get(ctx, "default", metav1.GetOptions{})
_, err := noxu2Client.CoreV1().Namespaces().Get(tCtx, "default", metav1.GetOptions{})
duration := time.Since(start).Seconds()
noxu2LatMeasure.update(duration)
if err != nil {