From 067dd97236646c328f2f3b4e0185a887187b0b34 Mon Sep 17 00:00:00 2001 From: Ashesh Vidyut Date: Fri, 30 May 2025 08:36:08 +0530 Subject: [PATCH 01/16] fix receiver renamed g to tl --- .gitignore | 1 + internal/grpctest/tlogger.go | 142 +++++++++++++++++------------------ 2 files changed, 72 insertions(+), 71 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..9f11b755a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ diff --git a/internal/grpctest/tlogger.go b/internal/grpctest/tlogger.go index f7f6da152..0cb4c7ffe 100644 --- a/internal/grpctest/tlogger.go +++ b/internal/grpctest/tlogger.go @@ -90,61 +90,61 @@ func getCallingPrefix(depth int) (string, error) { } // log logs the message with the specified parameters to the tLogger. -func (g *tLogger) log(ltype logType, depth int, format string, args ...any) { - g.mu.Lock() - defer g.mu.Unlock() +func (t *tLogger) log(ltype logType, depth int, format string, args ...any) { + t.mu.Lock() + defer t.mu.Unlock() prefix, err := getCallingPrefix(callingFrame + depth) if err != nil { - g.t.Error(err) + t.t.Error(err) return } args = append([]any{ltype.String() + " " + prefix}, args...) - args = append(args, fmt.Sprintf(" (t=+%s)", time.Since(g.start))) + args = append(args, fmt.Sprintf(" (t=+%s)", time.Since(t.start))) if format == "" { switch ltype { case errorLog: // fmt.Sprintln is used rather than fmt.Sprint because t.Log uses fmt.Sprintln behavior. - if g.expected(fmt.Sprintln(args...)) { - g.t.Log(args...) + if t.expected(fmt.Sprintln(args...)) { + t.t.Log(args...) } else { - g.t.Error(args...) + t.t.Error(args...) } case fatalLog: panic(fmt.Sprint(args...)) default: - g.t.Log(args...) + t.t.Log(args...) } } else { // Add formatting directives for the callingPrefix and timeSuffix. format = "%v " + format + "%s" switch ltype { case errorLog: - if g.expected(fmt.Sprintf(format, args...)) { - g.t.Logf(format, args...) + if t.expected(fmt.Sprintf(format, args...)) { + t.t.Logf(format, args...) } else { - g.t.Errorf(format, args...) + t.t.Errorf(format, args...) } case fatalLog: panic(fmt.Sprintf(format, args...)) default: - g.t.Logf(format, args...) + t.t.Logf(format, args...) } } } // Update updates the testing.T that the testing logger logs to. Should be done // before every test. It also initializes the tLogger if it has not already. -func (g *tLogger) Update(t *testing.T) { - g.mu.Lock() - defer g.mu.Unlock() - if !g.initialized { +func (t *tLogger) Update(t *testing.T) { + t.mu.Lock() + defer t.mu.Unlock() + if !t.initialized { grpclog.SetLoggerV2(TLogger) - g.initialized = true + t.initialized = true } - g.t = t - g.start = time.Now() - g.errors = map[*regexp.Regexp]int{} + t.t = t + t.start = time.Now() + t.errors = map[*regexp.Regexp]int{} } // ExpectError declares an error to be expected. For the next test, the first @@ -152,41 +152,41 @@ func (g *tLogger) Update(t *testing.T) { // to fail. "For the next test" includes all the time until the next call to // Update(). Note that if an expected error is not encountered, this will cause // the test to fail. -func (g *tLogger) ExpectError(expr string) { - g.ExpectErrorN(expr, 1) +func (t *tLogger) ExpectError(expr string) { + t.ExpectErrorN(expr, 1) } // ExpectErrorN declares an error to be expected n times. -func (g *tLogger) ExpectErrorN(expr string, n int) { - g.mu.Lock() - defer g.mu.Unlock() +func (t *tLogger) ExpectErrorN(expr string, n int) { + t.mu.Lock() + defer t.mu.Unlock() re, err := regexp.Compile(expr) if err != nil { - g.t.Error(err) + t.t.Error(err) return } - g.errors[re] += n + t.errors[re] += n } // EndTest checks if expected errors were not encountered. -func (g *tLogger) EndTest(t *testing.T) { - g.mu.Lock() - defer g.mu.Unlock() - for re, count := range g.errors { +func (t *tLogger) EndTest(t *testing.T) { + t.mu.Lock() + defer t.mu.Unlock() + for re, count := range t.errors { if count > 0 { t.Errorf("Expected error '%v' not encountered", re.String()) } } - g.errors = map[*regexp.Regexp]int{} + t.errors = map[*regexp.Regexp]int{} } // expected determines if the error string is protected or not. -func (g *tLogger) expected(s string) bool { - for re, count := range g.errors { +func (t *tLogger) expected(s string) bool { + for re, count := range t.errors { if re.FindStringIndex(s) != nil { - g.errors[re]-- + t.errors[re]-- if count <= 1 { - delete(g.errors, re) + delete(t.errors, re) } return true } @@ -194,70 +194,70 @@ func (g *tLogger) expected(s string) bool { return false } -func (g *tLogger) Info(args ...any) { - g.log(infoLog, 0, "", args...) +func (t *tLogger) Info(args ...any) { + t.log(infoLog, 0, "", args...) } -func (g *tLogger) Infoln(args ...any) { - g.log(infoLog, 0, "", args...) +func (t *tLogger) Infoln(args ...any) { + t.log(infoLog, 0, "", args...) } -func (g *tLogger) Infof(format string, args ...any) { - g.log(infoLog, 0, format, args...) +func (t *tLogger) Infof(format string, args ...any) { + t.log(infoLog, 0, format, args...) } -func (g *tLogger) InfoDepth(depth int, args ...any) { - g.log(infoLog, depth, "", args...) +func (t *tLogger) InfoDepth(depth int, args ...any) { + t.log(infoLog, depth, "", args...) } -func (g *tLogger) Warning(args ...any) { - g.log(warningLog, 0, "", args...) +func (t *tLogger) Warning(args ...any) { + t.log(warningLog, 0, "", args...) } -func (g *tLogger) Warningln(args ...any) { - g.log(warningLog, 0, "", args...) +func (t *tLogger) Warningln(args ...any) { + t.log(warningLog, 0, "", args...) } -func (g *tLogger) Warningf(format string, args ...any) { - g.log(warningLog, 0, format, args...) +func (t *tLogger) Warningf(format string, args ...any) { + t.log(warningLog, 0, format, args...) } -func (g *tLogger) WarningDepth(depth int, args ...any) { - g.log(warningLog, depth, "", args...) +func (t *tLogger) WarningDepth(depth int, args ...any) { + t.log(warningLog, depth, "", args...) } -func (g *tLogger) Error(args ...any) { - g.log(errorLog, 0, "", args...) +func (t *tLogger) Error(args ...any) { + t.log(errorLog, 0, "", args...) } -func (g *tLogger) Errorln(args ...any) { - g.log(errorLog, 0, "", args...) +func (t *tLogger) Errorln(args ...any) { + t.log(errorLog, 0, "", args...) } -func (g *tLogger) Errorf(format string, args ...any) { - g.log(errorLog, 0, format, args...) +func (t *tLogger) Errorf(format string, args ...any) { + t.log(errorLog, 0, format, args...) } -func (g *tLogger) ErrorDepth(depth int, args ...any) { - g.log(errorLog, depth, "", args...) +func (t *tLogger) ErrorDepth(depth int, args ...any) { + t.log(errorLog, depth, "", args...) } -func (g *tLogger) Fatal(args ...any) { - g.log(fatalLog, 0, "", args...) +func (t *tLogger) Fatal(args ...any) { + t.log(fatalLog, 0, "", args...) } -func (g *tLogger) Fatalln(args ...any) { - g.log(fatalLog, 0, "", args...) +func (t *tLogger) Fatalln(args ...any) { + t.log(fatalLog, 0, "", args...) } -func (g *tLogger) Fatalf(format string, args ...any) { - g.log(fatalLog, 0, format, args...) +func (t *tLogger) Fatalf(format string, args ...any) { + t.log(fatalLog, 0, format, args...) } -func (g *tLogger) FatalDepth(depth int, args ...any) { - g.log(fatalLog, depth, "", args...) +func (t *tLogger) FatalDepth(depth int, args ...any) { + t.log(fatalLog, depth, "", args...) } -func (g *tLogger) V(l int) bool { - return l <= g.v +func (t *tLogger) V(l int) bool { + return l <= t.v } From 3ecd1c1bbf90264968f8b747ae7da19a10279f32 Mon Sep 17 00:00:00 2001 From: Ashesh Vidyut Date: Fri, 30 May 2025 08:46:18 +0530 Subject: [PATCH 02/16] Init fixes --- internal/grpctest/tlogger.go | 165 +++++++++++++++++++---------------- 1 file changed, 88 insertions(+), 77 deletions(-) diff --git a/internal/grpctest/tlogger.go b/internal/grpctest/tlogger.go index 0cb4c7ffe..f986119cc 100644 --- a/internal/grpctest/tlogger.go +++ b/internal/grpctest/tlogger.go @@ -27,15 +27,16 @@ import ( "runtime" "strconv" "sync" + "sync/atomic" "testing" "time" "google.golang.org/grpc/grpclog" ) -// TLogger serves as the grpclog logger and is the interface through which +// tLoggerAtomic serves as the grpclog logger and is the interface through which // expected errors are declared in tests. -var TLogger *tLogger +var tLoggerAtomic atomic.Value const callingFrame = 4 @@ -73,13 +74,20 @@ type tLogger struct { } func init() { - TLogger = &tLogger{errors: map[*regexp.Regexp]int{}} + tLoggerAtomic.Store(&tLogger{errors: map[*regexp.Regexp]int{}}) vLevel := os.Getenv("GRPC_GO_LOG_VERBOSITY_LEVEL") if vl, err := strconv.Atoi(vLevel); err == nil { - TLogger.v = vl + if logger, ok := tLoggerAtomic.Load().(*tLogger); ok { + logger.v = vl + } } } +// getLogger returns the current logger instance. +func getLogger() *tLogger { + return tLoggerAtomic.Load().(*tLogger) +} + // getCallingPrefix returns the at the given depth from the stack. func getCallingPrefix(depth int) (string, error) { _, file, line, ok := runtime.Caller(depth) @@ -90,61 +98,62 @@ func getCallingPrefix(depth int) (string, error) { } // log logs the message with the specified parameters to the tLogger. -func (t *tLogger) log(ltype logType, depth int, format string, args ...any) { - t.mu.Lock() - defer t.mu.Unlock() +func (tl *tLogger) log(ltype logType, depth int, format string, args ...any) { + tl.mu.Lock() + defer tl.mu.Unlock() prefix, err := getCallingPrefix(callingFrame + depth) if err != nil { - t.t.Error(err) + tl.t.Error(err) return } args = append([]any{ltype.String() + " " + prefix}, args...) - args = append(args, fmt.Sprintf(" (t=+%s)", time.Since(t.start))) + args = append(args, fmt.Sprintf(" (t=+%s)", time.Since(tl.start))) if format == "" { switch ltype { case errorLog: - // fmt.Sprintln is used rather than fmt.Sprint because t.Log uses fmt.Sprintln behavior. - if t.expected(fmt.Sprintln(args...)) { - t.t.Log(args...) + // fmt.Sprintln is used rather than fmt.Sprint because tl.Log uses fmt.Sprintln behavior. + if tl.expected(fmt.Sprintln(args...)) { + tl.t.Log(args...) } else { - t.t.Error(args...) + tl.t.Error(args...) } case fatalLog: panic(fmt.Sprint(args...)) default: - t.t.Log(args...) + tl.t.Log(args...) } } else { // Add formatting directives for the callingPrefix and timeSuffix. format = "%v " + format + "%s" switch ltype { case errorLog: - if t.expected(fmt.Sprintf(format, args...)) { - t.t.Logf(format, args...) + if tl.expected(fmt.Sprintf(format, args...)) { + tl.t.Logf(format, args...) } else { - t.t.Errorf(format, args...) + tl.t.Errorf(format, args...) } case fatalLog: panic(fmt.Sprintf(format, args...)) default: - t.t.Logf(format, args...) + tl.t.Logf(format, args...) } } } // Update updates the testing.T that the testing logger logs to. Should be done // before every test. It also initializes the tLogger if it has not already. -func (t *tLogger) Update(t *testing.T) { - t.mu.Lock() - defer t.mu.Unlock() - if !t.initialized { - grpclog.SetLoggerV2(TLogger) - t.initialized = true +func Update(t *testing.T) { + logger := getLogger() + logger.mu.Lock() + defer logger.mu.Unlock() + if !logger.initialized { + grpclog.SetLoggerV2(logger) + logger.initialized = true } - t.t = t - t.start = time.Now() - t.errors = map[*regexp.Regexp]int{} + logger.t = t + logger.start = time.Now() + logger.errors = map[*regexp.Regexp]int{} } // ExpectError declares an error to be expected. For the next test, the first @@ -152,41 +161,43 @@ func (t *tLogger) Update(t *testing.T) { // to fail. "For the next test" includes all the time until the next call to // Update(). Note that if an expected error is not encountered, this will cause // the test to fail. -func (t *tLogger) ExpectError(expr string) { - t.ExpectErrorN(expr, 1) +func ExpectError(expr string) { + ExpectErrorN(expr, 1) } // ExpectErrorN declares an error to be expected n times. -func (t *tLogger) ExpectErrorN(expr string, n int) { - t.mu.Lock() - defer t.mu.Unlock() +func ExpectErrorN(expr string, n int) { + logger := getLogger() + logger.mu.Lock() + defer logger.mu.Unlock() re, err := regexp.Compile(expr) if err != nil { - t.t.Error(err) + logger.t.Error(err) return } - t.errors[re] += n + logger.errors[re] += n } // EndTest checks if expected errors were not encountered. -func (t *tLogger) EndTest(t *testing.T) { - t.mu.Lock() - defer t.mu.Unlock() - for re, count := range t.errors { +func EndTest(t *testing.T) { + logger := getLogger() + logger.mu.Lock() + defer logger.mu.Unlock() + for re, count := range logger.errors { if count > 0 { t.Errorf("Expected error '%v' not encountered", re.String()) } } - t.errors = map[*regexp.Regexp]int{} + logger.errors = map[*regexp.Regexp]int{} } // expected determines if the error string is protected or not. -func (t *tLogger) expected(s string) bool { - for re, count := range t.errors { +func (tl *tLogger) expected(s string) bool { + for re, count := range tl.errors { if re.FindStringIndex(s) != nil { - t.errors[re]-- + tl.errors[re]-- if count <= 1 { - delete(t.errors, re) + delete(tl.errors, re) } return true } @@ -194,70 +205,70 @@ func (t *tLogger) expected(s string) bool { return false } -func (t *tLogger) Info(args ...any) { - t.log(infoLog, 0, "", args...) +func (tl *tLogger) Info(args ...any) { + tl.log(infoLog, 0, "", args...) } -func (t *tLogger) Infoln(args ...any) { - t.log(infoLog, 0, "", args...) +func (tl *tLogger) Infoln(args ...any) { + tl.log(infoLog, 0, "", args...) } -func (t *tLogger) Infof(format string, args ...any) { - t.log(infoLog, 0, format, args...) +func (tl *tLogger) Infof(format string, args ...any) { + tl.log(infoLog, 0, format, args...) } -func (t *tLogger) InfoDepth(depth int, args ...any) { - t.log(infoLog, depth, "", args...) +func (tl *tLogger) InfoDepth(depth int, args ...any) { + tl.log(infoLog, depth, "", args...) } -func (t *tLogger) Warning(args ...any) { - t.log(warningLog, 0, "", args...) +func (tl *tLogger) Warning(args ...any) { + tl.log(warningLog, 0, "", args...) } -func (t *tLogger) Warningln(args ...any) { - t.log(warningLog, 0, "", args...) +func (tl *tLogger) Warningln(args ...any) { + tl.log(warningLog, 0, "", args...) } -func (t *tLogger) Warningf(format string, args ...any) { - t.log(warningLog, 0, format, args...) +func (tl *tLogger) Warningf(format string, args ...any) { + tl.log(warningLog, 0, format, args...) } -func (t *tLogger) WarningDepth(depth int, args ...any) { - t.log(warningLog, depth, "", args...) +func (tl *tLogger) WarningDepth(depth int, args ...any) { + tl.log(warningLog, depth, "", args...) } -func (t *tLogger) Error(args ...any) { - t.log(errorLog, 0, "", args...) +func (tl *tLogger) Error(args ...any) { + tl.log(errorLog, 0, "", args...) } -func (t *tLogger) Errorln(args ...any) { - t.log(errorLog, 0, "", args...) +func (tl *tLogger) Errorln(args ...any) { + tl.log(errorLog, 0, "", args...) } -func (t *tLogger) Errorf(format string, args ...any) { - t.log(errorLog, 0, format, args...) +func (tl *tLogger) Errorf(format string, args ...any) { + tl.log(errorLog, 0, format, args...) } -func (t *tLogger) ErrorDepth(depth int, args ...any) { - t.log(errorLog, depth, "", args...) +func (tl *tLogger) ErrorDepth(depth int, args ...any) { + tl.log(errorLog, depth, "", args...) } -func (t *tLogger) Fatal(args ...any) { - t.log(fatalLog, 0, "", args...) +func (tl *tLogger) Fatal(args ...any) { + tl.log(fatalLog, 0, "", args...) } -func (t *tLogger) Fatalln(args ...any) { - t.log(fatalLog, 0, "", args...) +func (tl *tLogger) Fatalln(args ...any) { + tl.log(fatalLog, 0, "", args...) } -func (t *tLogger) Fatalf(format string, args ...any) { - t.log(fatalLog, 0, format, args...) +func (tl *tLogger) Fatalf(format string, args ...any) { + tl.log(fatalLog, 0, format, args...) } -func (t *tLogger) FatalDepth(depth int, args ...any) { - t.log(fatalLog, depth, "", args...) +func (tl *tLogger) FatalDepth(depth int, args ...any) { + tl.log(fatalLog, depth, "", args...) } -func (t *tLogger) V(l int) bool { - return l <= t.v +func (tl *tLogger) V(l int) bool { + return l <= tl.v } From a855b59542b5150fefd24d9b2a06f3fe9d072e84 Mon Sep 17 00:00:00 2001 From: Ashesh Vidyut Date: Fri, 30 May 2025 08:48:03 +0530 Subject: [PATCH 03/16] fix var name --- internal/grpctest/tlogger.go | 38 ++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/internal/grpctest/tlogger.go b/internal/grpctest/tlogger.go index f986119cc..fa8a382fa 100644 --- a/internal/grpctest/tlogger.go +++ b/internal/grpctest/tlogger.go @@ -144,16 +144,16 @@ func (tl *tLogger) log(ltype logType, depth int, format string, args ...any) { // Update updates the testing.T that the testing logger logs to. Should be done // before every test. It also initializes the tLogger if it has not already. func Update(t *testing.T) { - logger := getLogger() - logger.mu.Lock() - defer logger.mu.Unlock() - if !logger.initialized { - grpclog.SetLoggerV2(logger) - logger.initialized = true + tl := getLogger() + tl.mu.Lock() + defer tl.mu.Unlock() + if !tl.initialized { + grpclog.SetLoggerV2(tl) + tl.initialized = true } - logger.t = t - logger.start = time.Now() - logger.errors = map[*regexp.Regexp]int{} + tl.t = t + tl.start = time.Now() + tl.errors = map[*regexp.Regexp]int{} } // ExpectError declares an error to be expected. For the next test, the first @@ -167,28 +167,28 @@ func ExpectError(expr string) { // ExpectErrorN declares an error to be expected n times. func ExpectErrorN(expr string, n int) { - logger := getLogger() - logger.mu.Lock() - defer logger.mu.Unlock() + tl := getLogger() + tl.mu.Lock() + defer tl.mu.Unlock() re, err := regexp.Compile(expr) if err != nil { - logger.t.Error(err) + tl.t.Error(err) return } - logger.errors[re] += n + tl.errors[re] += n } // EndTest checks if expected errors were not encountered. func EndTest(t *testing.T) { - logger := getLogger() - logger.mu.Lock() - defer logger.mu.Unlock() - for re, count := range logger.errors { + tl := getLogger() + tl.mu.Lock() + defer tl.mu.Unlock() + for re, count := range tl.errors { if count > 0 { t.Errorf("Expected error '%v' not encountered", re.String()) } } - logger.errors = map[*regexp.Regexp]int{} + tl.errors = map[*regexp.Regexp]int{} } // expected determines if the error string is protected or not. From aa41fa928c57ca601bdd11a9be3cd19076b42395 Mon Sep 17 00:00:00 2001 From: Ashesh Vidyut Date: Fri, 30 May 2025 08:57:31 +0530 Subject: [PATCH 04/16] update the function calls --- encoding/encoding_test.go | 2 +- internal/grpctest/grpctest.go | 4 ++-- internal/grpctest/tlogger_test.go | 9 +++++---- internal/transport/keepalive_test.go | 6 +++--- orca/producer_test.go | 2 +- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/encoding/encoding_test.go b/encoding/encoding_test.go index 19769146f..cc9130fac 100644 --- a/encoding/encoding_test.go +++ b/encoding/encoding_test.go @@ -112,7 +112,7 @@ func (c *errProtoCodec) Name() string { // Tests the case where encoding fails on the server. Verifies that there is // no panic and that the encoding error is propagated to the client. func (s) TestEncodeDoesntPanicOnServer(t *testing.T) { - grpctest.TLogger.ExpectError("grpc: server failed to encode response") + grpctest.ExpectError("grpc: server failed to encode response") // Create a codec that errors when encoding messages. encodingErr := errors.New("encoding failed") diff --git a/internal/grpctest/grpctest.go b/internal/grpctest/grpctest.go index b8bc38580..be62c2a3c 100644 --- a/internal/grpctest/grpctest.go +++ b/internal/grpctest/grpctest.go @@ -53,7 +53,7 @@ type Tester struct{} // Setup updates the tlogger. func (Tester) Setup(t *testing.T) { - TLogger.Update(t) + Update(t) // TODO: There is one final leak around closing connections without completely // draining the recvBuffer that has yet to be resolved. All other leaks have been // completely addressed, and this can be turned back on as soon as this issue is @@ -75,7 +75,7 @@ func (Tester) Teardown(t *testing.T) { if atomic.LoadUint32(&lcFailed) == 1 { t.Log("Goroutine leak check disabled for future tests") } - TLogger.EndTest(t) + EndTest(t) } // Interface defines Tester's methods for use in this package. diff --git a/internal/grpctest/tlogger_test.go b/internal/grpctest/tlogger_test.go index 364f1432e..bc3587dd9 100644 --- a/internal/grpctest/tlogger_test.go +++ b/internal/grpctest/tlogger_test.go @@ -66,10 +66,11 @@ func (s) TestWarningDepth(*testing.T) { func (s) TestError(*testing.T) { const numErrors = 10 - TLogger.ExpectError("Expected error") - TLogger.ExpectError("Expected ln error") - TLogger.ExpectError("Expected formatted error") - TLogger.ExpectErrorN("Expected repeated error", numErrors) + Update(t) + ExpectError("Expected error") + ExpectError("Expected ln error") + ExpectError("Expected formatted error") + ExpectErrorN("Expected repeated error", numErrors) grpclog.Error("Expected", "error") grpclog.Errorln("Expected", "ln", "error") grpclog.Errorf("%v %v %v", "Expected", "formatted", "error") diff --git a/internal/transport/keepalive_test.go b/internal/transport/keepalive_test.go index 037b0b1c1..0bd7ba356 100644 --- a/internal/transport/keepalive_test.go +++ b/internal/transport/keepalive_test.go @@ -398,7 +398,7 @@ func (s) TestKeepaliveClientStaysHealthyWithResponsiveServer(t *testing.T) { // explicitly makes sure the fix works and the client sends a ping every [Time] // period. func (s) TestKeepaliveClientFrequency(t *testing.T) { - grpctest.TLogger.ExpectError("Client received GoAway with error code ENHANCE_YOUR_CALM and debug data equal to ASCII \"too_many_pings\"") + grpctest.ExpectError("Client received GoAway with error code ENHANCE_YOUR_CALM and debug data equal to ASCII \"too_many_pings\"") serverConfig := &ServerConfig{ KeepalivePolicy: keepalive.EnforcementPolicy{ @@ -430,7 +430,7 @@ func (s) TestKeepaliveClientFrequency(t *testing.T) { // (when there are no active streams), based on the configured // EnforcementPolicy. func (s) TestKeepaliveServerEnforcementWithAbusiveClientNoRPC(t *testing.T) { - grpctest.TLogger.ExpectError("Client received GoAway with error code ENHANCE_YOUR_CALM and debug data equal to ASCII \"too_many_pings\"") + grpctest.ExpectError("Client received GoAway with error code ENHANCE_YOUR_CALM and debug data equal to ASCII \"too_many_pings\"") serverConfig := &ServerConfig{ KeepalivePolicy: keepalive.EnforcementPolicy{ @@ -461,7 +461,7 @@ func (s) TestKeepaliveServerEnforcementWithAbusiveClientNoRPC(t *testing.T) { // (even when there is an active stream), based on the configured // EnforcementPolicy. func (s) TestKeepaliveServerEnforcementWithAbusiveClientWithRPC(t *testing.T) { - grpctest.TLogger.ExpectError("Client received GoAway with error code ENHANCE_YOUR_CALM and debug data equal to ASCII \"too_many_pings\"") + grpctest.ExpectError("Client received GoAway with error code ENHANCE_YOUR_CALM and debug data equal to ASCII \"too_many_pings\"") serverConfig := &ServerConfig{ KeepalivePolicy: keepalive.EnforcementPolicy{ diff --git a/orca/producer_test.go b/orca/producer_test.go index adf030cc1..76d30f552 100644 --- a/orca/producer_test.go +++ b/orca/producer_test.go @@ -266,7 +266,7 @@ func (f *fakeORCAService) StreamCoreMetrics(req *v3orcaservicepb.OrcaLoadReportR // TestProducerBackoff verifies that the ORCA producer applies the proper // backoff after stream failures. func (s) TestProducerBackoff(t *testing.T) { - grpctest.TLogger.ExpectErrorN("injected error", 4) + grpctest.ExpectErrorN("injected error", 4) ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) defer cancel() From bee5800d5648e24540ad1530a1a65979a9845976 Mon Sep 17 00:00:00 2001 From: Ashesh Vidyut Date: Fri, 30 May 2025 09:00:03 +0530 Subject: [PATCH 05/16] fix variable --- internal/grpctest/tlogger_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/grpctest/tlogger_test.go b/internal/grpctest/tlogger_test.go index bc3587dd9..1029a00b9 100644 --- a/internal/grpctest/tlogger_test.go +++ b/internal/grpctest/tlogger_test.go @@ -64,7 +64,7 @@ func (s) TestWarningDepth(*testing.T) { grpclog.WarningDepth(0, "Warning", "depth", "message.") } -func (s) TestError(*testing.T) { +func (s) TestError(t *testing.T) { const numErrors = 10 Update(t) ExpectError("Expected error") From 0214e37c00414166e8f14922df98b0e9ce88fe51 Mon Sep 17 00:00:00 2001 From: Ashesh Vidyut Date: Fri, 30 May 2025 09:04:04 +0530 Subject: [PATCH 06/16] fixing tests to match the tlogger changes --- test/end2end_test.go | 4 ++-- test/goaway_test.go | 2 +- test/healthcheck_test.go | 2 +- test/metadata_test.go | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/end2end_test.go b/test/end2end_test.go index 584c90ca3..ad80c9c5a 100644 --- a/test/end2end_test.go +++ b/test/end2end_test.go @@ -5312,7 +5312,7 @@ func (s) TestStatusInvalidUTF8Message(t *testing.T) { // will fail to marshal the status because of the invalid utf8 message. Details // will be dropped when sending. func (s) TestStatusInvalidUTF8Details(t *testing.T) { - grpctest.TLogger.ExpectError("Failed to marshal rpc status") + grpctest.ExpectError("Failed to marshal rpc status") var ( origMsg = string([]byte{0xff, 0xfe, 0xfd}) @@ -6323,7 +6323,7 @@ func (s) TestServerClosesConn(t *testing.T) { // TestNilStatsHandler ensures we do not panic as a result of a nil stats // handler. func (s) TestNilStatsHandler(t *testing.T) { - grpctest.TLogger.ExpectErrorN("ignoring nil parameter", 2) + grpctest.ExpectErrorN("ignoring nil parameter", 2) ss := &stubserver.StubServer{ UnaryCallF: func(context.Context, *testpb.SimpleRequest) (*testpb.SimpleResponse, error) { return &testpb.SimpleResponse{}, nil diff --git a/test/goaway_test.go b/test/goaway_test.go index 076412da7..6f90eccef 100644 --- a/test/goaway_test.go +++ b/test/goaway_test.go @@ -121,7 +121,7 @@ func (s) TestDetailedGoAwayErrorOnGracefulClosePropagatesToRPCError(t *testing.T } func (s) TestDetailedGoAwayErrorOnAbruptClosePropagatesToRPCError(t *testing.T) { - grpctest.TLogger.ExpectError("Client received GoAway with error code ENHANCE_YOUR_CALM and debug data equal to ASCII \"too_many_pings\"") + grpctest.ExpectError("Client received GoAway with error code ENHANCE_YOUR_CALM and debug data equal to ASCII \"too_many_pings\"") // set the min keepalive time very low so that this test can take // a reasonable amount of time prev := internal.KeepaliveMinPingTime diff --git a/test/healthcheck_test.go b/test/healthcheck_test.go index 0f7ec54a8..29fa3228b 100644 --- a/test/healthcheck_test.go +++ b/test/healthcheck_test.go @@ -254,7 +254,7 @@ func (s) TestHealthCheckWatchStateChange(t *testing.T) { // If Watch returns Unimplemented, then the ClientConn should go into READY state. func (s) TestHealthCheckHealthServerNotRegistered(t *testing.T) { - grpctest.TLogger.ExpectError("Subchannel health check is unimplemented at server side, thus health check is disabled") + grpctest.ExpectError("Subchannel health check is unimplemented at server side, thus health check is disabled") s := grpc.NewServer() lis, err := net.Listen("tcp", "localhost:0") if err != nil { diff --git a/test/metadata_test.go b/test/metadata_test.go index 57139a8d9..6c469d2f7 100644 --- a/test/metadata_test.go +++ b/test/metadata_test.go @@ -37,7 +37,7 @@ import ( ) func (s) TestInvalidMetadata(t *testing.T) { - grpctest.TLogger.ExpectErrorN("stream: failed to validate md when setting trailer", 5) + grpctest.ExpectErrorN("stream: failed to validate md when setting trailer", 5) tests := []struct { name string From 75b489c89723cf3960c8c3709bd083ef0189dd66 Mon Sep 17 00:00:00 2001 From: Ashesh Vidyut Date: Fri, 30 May 2025 09:11:30 +0530 Subject: [PATCH 07/16] fixes the build and passing all tests --- clientconn_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clientconn_test.go b/clientconn_test.go index 9cca5a8eb..68c224140 100644 --- a/clientconn_test.go +++ b/clientconn_test.go @@ -702,7 +702,7 @@ func (s) TestResolverEmptyUpdateNotPanic(t *testing.T) { } func (s) TestClientUpdatesParamsAfterGoAway(t *testing.T) { - grpctest.TLogger.ExpectError("Client received GoAway with error code ENHANCE_YOUR_CALM and debug data equal to ASCII \"too_many_pings\"") + grpctest.ExpectError("Client received GoAway with error code ENHANCE_YOUR_CALM and debug data equal to ASCII \"too_many_pings\"") lis, err := net.Listen("tcp", "localhost:0") if err != nil { From 925f81113006e63bc9e239ff01f2586769f2bb15 Mon Sep 17 00:00:00 2001 From: Ashesh Vidyut Date: Fri, 30 May 2025 09:24:55 +0530 Subject: [PATCH 08/16] add tests --- internal/grpctest/tlogger_test.go | 93 +++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/internal/grpctest/tlogger_test.go b/internal/grpctest/tlogger_test.go index 1029a00b9..0e0e2f220 100644 --- a/internal/grpctest/tlogger_test.go +++ b/internal/grpctest/tlogger_test.go @@ -19,6 +19,9 @@ package grpctest import ( + "os" + "regexp" + "strconv" "testing" "google.golang.org/grpc/grpclog" @@ -78,3 +81,93 @@ func (s) TestError(t *testing.T) { grpclog.Error("Expected repeated error") } } + +func (s) TestInit(t *testing.T) { + // Test initial state + logger := getLogger() + if logger == nil { + t.Fatal("getLogger() returned nil") + } + if logger.errors == nil { + t.Error("logger.errors is nil") + } + if len(logger.errors) != 0 { + t.Errorf("logger.errors = %v; want empty map", logger.errors) + } + if logger.initialized { + t.Error("logger.initialized = true; want false") + } + if logger.t != nil { + t.Error("logger.t is not nil") + } + if !logger.start.IsZero() { + t.Error("logger.start is not zero") + } +} + +func (s) TestInitVerbosityLevel(t *testing.T) { + // Save original env var + origLevel := os.Getenv("GRPC_GO_LOG_VERBOSITY_LEVEL") + defer os.Setenv("GRPC_GO_LOG_VERBOSITY_LEVEL", origLevel) + + // Test with valid verbosity level + testLevel := "2" + os.Setenv("GRPC_GO_LOG_VERBOSITY_LEVEL", testLevel) + + // Create new logger to trigger init + tLoggerAtomic.Store(&tLogger{errors: map[*regexp.Regexp]int{}}) + vLevel := os.Getenv("GRPC_GO_LOG_VERBOSITY_LEVEL") + if vl, err := strconv.Atoi(vLevel); err == nil { + if logger, ok := tLoggerAtomic.Load().(*tLogger); ok { + logger.v = vl + } + } + + // Verify verbosity level + logger := getLogger() + if logger.v != 2 { + t.Errorf("logger.v = %d; want 2", logger.v) + } + + // Test with invalid verbosity level + os.Setenv("GRPC_GO_LOG_VERBOSITY_LEVEL", "invalid") + + // Create new logger to trigger init + tLoggerAtomic.Store(&tLogger{errors: map[*regexp.Regexp]int{}}) + vLevel = os.Getenv("GRPC_GO_LOG_VERBOSITY_LEVEL") + if vl, err := strconv.Atoi(vLevel); err == nil { + if logger, ok := tLoggerAtomic.Load().(*tLogger); ok { + logger.v = vl + } + } + + // Verify verbosity level remains unchanged + logger = getLogger() + if logger.v != 2 { + t.Errorf("logger.v = %d; want 2", logger.v) + } +} + +func (s) TestAtomicValue(t *testing.T) { + // Test atomic value storage and retrieval + origLogger := getLogger() + + // Create new logger + newLogger := &tLogger{errors: map[*regexp.Regexp]int{}} + tLoggerAtomic.Store(newLogger) + + // Verify new logger is retrieved + retrievedLogger := getLogger() + if retrievedLogger != newLogger { + t.Error("getLogger() did not return the newly stored logger") + } + + // Restore original logger + tLoggerAtomic.Store(origLogger) + + // Verify original logger is retrieved + retrievedLogger = getLogger() + if retrievedLogger != origLogger { + t.Error("getLogger() did not return the original logger after restore") + } +} From 0e17dc033b55eb9f623afade35ab9c956d825795 Mon Sep 17 00:00:00 2001 From: Ashesh Vidyut Date: Fri, 30 May 2025 09:27:15 +0530 Subject: [PATCH 09/16] fix init tests --- internal/grpctest/tlogger_test.go | 32 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/internal/grpctest/tlogger_test.go b/internal/grpctest/tlogger_test.go index 0e0e2f220..4693fce12 100644 --- a/internal/grpctest/tlogger_test.go +++ b/internal/grpctest/tlogger_test.go @@ -83,6 +83,9 @@ func (s) TestError(t *testing.T) { } func (s) TestInit(t *testing.T) { + // Reset the atomic value + tLoggerAtomic.Store(&tLogger{errors: map[*regexp.Regexp]int{}}) + // Test initial state logger := getLogger() if logger == nil { @@ -106,25 +109,23 @@ func (s) TestInit(t *testing.T) { } func (s) TestInitVerbosityLevel(t *testing.T) { - // Save original env var + // Save original env var and reset atomic value origLevel := os.Getenv("GRPC_GO_LOG_VERBOSITY_LEVEL") defer os.Setenv("GRPC_GO_LOG_VERBOSITY_LEVEL", origLevel) + tLoggerAtomic.Store(&tLogger{errors: map[*regexp.Regexp]int{}}) // Test with valid verbosity level testLevel := "2" os.Setenv("GRPC_GO_LOG_VERBOSITY_LEVEL", testLevel) - // Create new logger to trigger init - tLoggerAtomic.Store(&tLogger{errors: map[*regexp.Regexp]int{}}) + // Initialize logger with verbosity level + logger := getLogger() vLevel := os.Getenv("GRPC_GO_LOG_VERBOSITY_LEVEL") if vl, err := strconv.Atoi(vLevel); err == nil { - if logger, ok := tLoggerAtomic.Load().(*tLogger); ok { - logger.v = vl - } + logger.v = vl } // Verify verbosity level - logger := getLogger() if logger.v != 2 { t.Errorf("logger.v = %d; want 2", logger.v) } @@ -132,25 +133,24 @@ func (s) TestInitVerbosityLevel(t *testing.T) { // Test with invalid verbosity level os.Setenv("GRPC_GO_LOG_VERBOSITY_LEVEL", "invalid") - // Create new logger to trigger init + // Reset atomic value and initialize new logger tLoggerAtomic.Store(&tLogger{errors: map[*regexp.Regexp]int{}}) + logger = getLogger() vLevel = os.Getenv("GRPC_GO_LOG_VERBOSITY_LEVEL") if vl, err := strconv.Atoi(vLevel); err == nil { - if logger, ok := tLoggerAtomic.Load().(*tLogger); ok { - logger.v = vl - } + logger.v = vl } - // Verify verbosity level remains unchanged - logger = getLogger() - if logger.v != 2 { - t.Errorf("logger.v = %d; want 2", logger.v) + // Verify verbosity level remains at default (0) for invalid input + if logger.v != 0 { + t.Errorf("logger.v = %d; want 0", logger.v) } } func (s) TestAtomicValue(t *testing.T) { - // Test atomic value storage and retrieval + // Save original logger origLogger := getLogger() + defer tLoggerAtomic.Store(origLogger) // Create new logger newLogger := &tLogger{errors: map[*regexp.Regexp]int{}} From 6e57a730de26d0242de6c6711c8be05cc60828ca Mon Sep 17 00:00:00 2001 From: Ashesh Vidyut Date: Fri, 30 May 2025 09:30:41 +0530 Subject: [PATCH 10/16] removed update --- internal/grpctest/tlogger_test.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/internal/grpctest/tlogger_test.go b/internal/grpctest/tlogger_test.go index 4693fce12..2c10ec249 100644 --- a/internal/grpctest/tlogger_test.go +++ b/internal/grpctest/tlogger_test.go @@ -69,7 +69,6 @@ func (s) TestWarningDepth(*testing.T) { func (s) TestError(t *testing.T) { const numErrors = 10 - Update(t) ExpectError("Expected error") ExpectError("Expected ln error") ExpectError("Expected formatted error") @@ -85,7 +84,7 @@ func (s) TestError(t *testing.T) { func (s) TestInit(t *testing.T) { // Reset the atomic value tLoggerAtomic.Store(&tLogger{errors: map[*regexp.Regexp]int{}}) - + // Test initial state logger := getLogger() if logger == nil { @@ -117,7 +116,7 @@ func (s) TestInitVerbosityLevel(t *testing.T) { // Test with valid verbosity level testLevel := "2" os.Setenv("GRPC_GO_LOG_VERBOSITY_LEVEL", testLevel) - + // Initialize logger with verbosity level logger := getLogger() vLevel := os.Getenv("GRPC_GO_LOG_VERBOSITY_LEVEL") @@ -132,7 +131,7 @@ func (s) TestInitVerbosityLevel(t *testing.T) { // Test with invalid verbosity level os.Setenv("GRPC_GO_LOG_VERBOSITY_LEVEL", "invalid") - + // Reset atomic value and initialize new logger tLoggerAtomic.Store(&tLogger{errors: map[*regexp.Regexp]int{}}) logger = getLogger() @@ -151,20 +150,20 @@ func (s) TestAtomicValue(t *testing.T) { // Save original logger origLogger := getLogger() defer tLoggerAtomic.Store(origLogger) - + // Create new logger newLogger := &tLogger{errors: map[*regexp.Regexp]int{}} tLoggerAtomic.Store(newLogger) - + // Verify new logger is retrieved retrievedLogger := getLogger() if retrievedLogger != newLogger { t.Error("getLogger() did not return the newly stored logger") } - + // Restore original logger tLoggerAtomic.Store(origLogger) - + // Verify original logger is retrieved retrievedLogger = getLogger() if retrievedLogger != origLogger { From 0017513846f110a369cc11c3af305855ad5f0bfb Mon Sep 17 00:00:00 2001 From: Ashesh Vidyut Date: Fri, 30 May 2025 09:33:59 +0530 Subject: [PATCH 11/16] add Update so that CI passes --- internal/grpctest/tlogger_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/grpctest/tlogger_test.go b/internal/grpctest/tlogger_test.go index 2c10ec249..8e65b04ca 100644 --- a/internal/grpctest/tlogger_test.go +++ b/internal/grpctest/tlogger_test.go @@ -68,6 +68,7 @@ func (s) TestWarningDepth(*testing.T) { } func (s) TestError(t *testing.T) { + Update(t) const numErrors = 10 ExpectError("Expected error") ExpectError("Expected ln error") From 0e7f31798aa0789c8bb4f3faf1388a4086f543f3 Mon Sep 17 00:00:00 2001 From: Ashesh Vidyut Date: Fri, 30 May 2025 09:45:15 +0530 Subject: [PATCH 12/16] remove update and testing t --- internal/grpctest/tlogger_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/grpctest/tlogger_test.go b/internal/grpctest/tlogger_test.go index 8e65b04ca..c72dc485f 100644 --- a/internal/grpctest/tlogger_test.go +++ b/internal/grpctest/tlogger_test.go @@ -67,8 +67,7 @@ func (s) TestWarningDepth(*testing.T) { grpclog.WarningDepth(0, "Warning", "depth", "message.") } -func (s) TestError(t *testing.T) { - Update(t) +func (s) TestError(*testing.T) { const numErrors = 10 ExpectError("Expected error") ExpectError("Expected ln error") From af76c43432d9b5abb5a105b8b947df5e62d91a8b Mon Sep 17 00:00:00 2001 From: Ashesh Vidyut Date: Fri, 30 May 2025 09:56:49 +0530 Subject: [PATCH 13/16] rename variable --- internal/grpctest/tlogger_test.go | 44 +++++++++++++++---------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/internal/grpctest/tlogger_test.go b/internal/grpctest/tlogger_test.go index c72dc485f..614806ef1 100644 --- a/internal/grpctest/tlogger_test.go +++ b/internal/grpctest/tlogger_test.go @@ -86,24 +86,24 @@ func (s) TestInit(t *testing.T) { tLoggerAtomic.Store(&tLogger{errors: map[*regexp.Regexp]int{}}) // Test initial state - logger := getLogger() - if logger == nil { + tl := getLogger() + if tl == nil { t.Fatal("getLogger() returned nil") } - if logger.errors == nil { - t.Error("logger.errors is nil") + if tl.errors == nil { + t.Error("tl.errors is nil") } - if len(logger.errors) != 0 { - t.Errorf("logger.errors = %v; want empty map", logger.errors) + if len(tl.errors) != 0 { + t.Errorf("tl.errors = %v; want empty map", tl.errors) } - if logger.initialized { - t.Error("logger.initialized = true; want false") + if tl.initialized { + t.Error("tl.initialized = true; want false") } - if logger.t != nil { - t.Error("logger.t is not nil") + if tl.t != nil { + t.Error("tl.t is not nil") } - if !logger.start.IsZero() { - t.Error("logger.start is not zero") + if !tl.start.IsZero() { + t.Error("tl.start is not zero") } } @@ -117,32 +117,32 @@ func (s) TestInitVerbosityLevel(t *testing.T) { testLevel := "2" os.Setenv("GRPC_GO_LOG_VERBOSITY_LEVEL", testLevel) - // Initialize logger with verbosity level - logger := getLogger() + // Initialize tl with verbosity level + tl := getLogger() vLevel := os.Getenv("GRPC_GO_LOG_VERBOSITY_LEVEL") if vl, err := strconv.Atoi(vLevel); err == nil { - logger.v = vl + tl.v = vl } // Verify verbosity level - if logger.v != 2 { - t.Errorf("logger.v = %d; want 2", logger.v) + if tl.v != 2 { + t.Errorf("tl.v = %d; want 2", tl.v) } // Test with invalid verbosity level os.Setenv("GRPC_GO_LOG_VERBOSITY_LEVEL", "invalid") - // Reset atomic value and initialize new logger + // Reset atomic value and initialize new tl tLoggerAtomic.Store(&tLogger{errors: map[*regexp.Regexp]int{}}) - logger = getLogger() + tl = getLogger() vLevel = os.Getenv("GRPC_GO_LOG_VERBOSITY_LEVEL") if vl, err := strconv.Atoi(vLevel); err == nil { - logger.v = vl + tl.v = vl } // Verify verbosity level remains at default (0) for invalid input - if logger.v != 0 { - t.Errorf("logger.v = %d; want 0", logger.v) + if tl.v != 0 { + t.Errorf("tl.v = %d; want 0", tl.v) } } From ef054482040a48ca0c44c258c1c1a9abd0098362 Mon Sep 17 00:00:00 2001 From: Ashesh Vidyut Date: Tue, 3 Jun 2025 11:18:05 +0530 Subject: [PATCH 14/16] addressed some pr comments --- internal/grpctest/tlogger.go | 5 ++--- internal/grpctest/tlogger_test.go | 6 ++---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/internal/grpctest/tlogger.go b/internal/grpctest/tlogger.go index fa8a382fa..ae8af3fa9 100644 --- a/internal/grpctest/tlogger.go +++ b/internal/grpctest/tlogger.go @@ -77,9 +77,8 @@ func init() { tLoggerAtomic.Store(&tLogger{errors: map[*regexp.Regexp]int{}}) vLevel := os.Getenv("GRPC_GO_LOG_VERBOSITY_LEVEL") if vl, err := strconv.Atoi(vLevel); err == nil { - if logger, ok := tLoggerAtomic.Load().(*tLogger); ok { - logger.v = vl - } + lgr := getLogger() + lgr.v = vl } } diff --git a/internal/grpctest/tlogger_test.go b/internal/grpctest/tlogger_test.go index 614806ef1..b777b8531 100644 --- a/internal/grpctest/tlogger_test.go +++ b/internal/grpctest/tlogger_test.go @@ -109,13 +109,11 @@ func (s) TestInit(t *testing.T) { func (s) TestInitVerbosityLevel(t *testing.T) { // Save original env var and reset atomic value - origLevel := os.Getenv("GRPC_GO_LOG_VERBOSITY_LEVEL") - defer os.Setenv("GRPC_GO_LOG_VERBOSITY_LEVEL", origLevel) tLoggerAtomic.Store(&tLogger{errors: map[*regexp.Regexp]int{}}) // Test with valid verbosity level testLevel := "2" - os.Setenv("GRPC_GO_LOG_VERBOSITY_LEVEL", testLevel) + t.Setenv("GRPC_GO_LOG_VERBOSITY_LEVEL", testLevel) // Initialize tl with verbosity level tl := getLogger() @@ -130,7 +128,7 @@ func (s) TestInitVerbosityLevel(t *testing.T) { } // Test with invalid verbosity level - os.Setenv("GRPC_GO_LOG_VERBOSITY_LEVEL", "invalid") + t.Setenv("GRPC_GO_LOG_VERBOSITY_LEVEL", "invalid") // Reset atomic value and initialize new tl tLoggerAtomic.Store(&tLogger{errors: map[*regexp.Regexp]int{}}) From a828e41cf03e5938ca2eb94fc689647ec4794b53 Mon Sep 17 00:00:00 2001 From: Ashesh Vidyut Date: Tue, 3 Jun 2025 11:20:12 +0530 Subject: [PATCH 15/16] remove .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .gitignore diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 9f11b755a..000000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.idea/ From 6f7dde80a816856c0d06733d5b46a9676280fe24 Mon Sep 17 00:00:00 2001 From: Ashesh Vidyut Date: Tue, 3 Jun 2025 12:41:46 +0530 Subject: [PATCH 16/16] removed verbosity level test and renamed TestAtomicValue to TestGetLogger --- internal/grpctest/tlogger_test.go | 41 +------------------------------ 1 file changed, 1 insertion(+), 40 deletions(-) diff --git a/internal/grpctest/tlogger_test.go b/internal/grpctest/tlogger_test.go index b777b8531..475ca7844 100644 --- a/internal/grpctest/tlogger_test.go +++ b/internal/grpctest/tlogger_test.go @@ -19,9 +19,7 @@ package grpctest import ( - "os" "regexp" - "strconv" "testing" "google.golang.org/grpc/grpclog" @@ -107,44 +105,7 @@ func (s) TestInit(t *testing.T) { } } -func (s) TestInitVerbosityLevel(t *testing.T) { - // Save original env var and reset atomic value - tLoggerAtomic.Store(&tLogger{errors: map[*regexp.Regexp]int{}}) - - // Test with valid verbosity level - testLevel := "2" - t.Setenv("GRPC_GO_LOG_VERBOSITY_LEVEL", testLevel) - - // Initialize tl with verbosity level - tl := getLogger() - vLevel := os.Getenv("GRPC_GO_LOG_VERBOSITY_LEVEL") - if vl, err := strconv.Atoi(vLevel); err == nil { - tl.v = vl - } - - // Verify verbosity level - if tl.v != 2 { - t.Errorf("tl.v = %d; want 2", tl.v) - } - - // Test with invalid verbosity level - t.Setenv("GRPC_GO_LOG_VERBOSITY_LEVEL", "invalid") - - // Reset atomic value and initialize new tl - tLoggerAtomic.Store(&tLogger{errors: map[*regexp.Regexp]int{}}) - tl = getLogger() - vLevel = os.Getenv("GRPC_GO_LOG_VERBOSITY_LEVEL") - if vl, err := strconv.Atoi(vLevel); err == nil { - tl.v = vl - } - - // Verify verbosity level remains at default (0) for invalid input - if tl.v != 0 { - t.Errorf("tl.v = %d; want 0", tl.v) - } -} - -func (s) TestAtomicValue(t *testing.T) { +func (s) TestGetLogger(t *testing.T) { // Save original logger origLogger := getLogger() defer tLoggerAtomic.Store(origLogger)