refactor (events): QOL fix: turn off events for tests. (#3163)

This commit is contained in:
Jim authored and GitHub committed 2023-04-14 20:01:14 -04:00
1 parent 8c265bf7c1
commit a4f54cb98f
15 files changed
+196 -55

No files matched your search

+18 -35
View File
@@ -7,7 +7,6 @@ import (
"context"
"encoding/json"
"fmt"
"io"
"net"
"os"
"strconv"
@@ -409,10 +408,11 @@ type TestControllerOpts struct {
// If true, the controller will not be started
DisableAutoStart bool
// DisableEventing, if true the test controller will not create events
// You must not run the test in parallel (no calls to t.Parallel) since the
// this option relies on modifying the system wide default eventer.
DisableEventing bool
// EnableEventing, if true the test controller will create sys and error
// events. You must not run the test in parallel (no calls to t.Parallel)
// since the this option relies on modifying the system wide default
// eventer.
EnableEventing bool
// DisableAuthorizationFailures will still cause authz checks to be
// performed but they won't cause 403 Forbidden. Useful for API-level
@@ -613,39 +613,22 @@ func TestControllerConfig(t testing.TB, ctx context.Context, tc *TestController,
}
opts.Config.Controller.Scheduler.JobRunIntervalDuration = opts.SchedulerRunJobInterval
switch {
case opts.DisableEventing:
if opts.EnableEventing {
opts.Config.Eventing = &event.EventerConfig{
AuditEnabled: false,
ObservationsEnabled: false,
SysEventsEnabled: false,
}
testLogger := hclog.New(&hclog.LoggerOptions{
Mutex: tc.b.StderrLock,
Output: io.Discard,
})
e, err := event.NewEventer(
testLogger,
tc.b.StderrLock,
opts.Config.Controller.Name,
*opts.Config.Eventing,
)
if err != nil {
t.Fatal(err)
}
tc.b.Eventer = e
event.TestWithoutEventing(t) // this ensures the sys eventer will also stop eventing
default:
serverName, err := os.Hostname()
if err != nil {
t.Fatal(err)
}
serverName = fmt.Sprintf("%s/controller", serverName)
if err := tc.b.SetupEventing(tc.b.Logger, tc.b.StderrLock, serverName, base.WithEventerConfig(opts.Config.Eventing)); err != nil {
t.Fatal(err)
AuditEnabled: true,
ObservationsEnabled: true,
SysEventsEnabled: true,
ErrorEventsDisabled: true,
}
}
serverName, err := os.Hostname()
if err != nil {
t.Fatal(err)
}
serverName = fmt.Sprintf("%s/controller", serverName)
if err := tc.b.SetupEventing(tc.b.Logger, tc.b.StderrLock, serverName, base.WithEventerConfig(opts.Config.Eventing)); err != nil {
t.Fatal(err)
}
if opts.WorkerStatusGracePeriodDuration != 0 {
opts.Config.Controller.WorkerStatusGracePeriodDuration = opts.WorkerStatusGracePeriodDuration