You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "lostluck (via GitHub)" <gi...@apache.org> on 2023/09/12 18:33:56 UTC

[GitHub] [beam] lostluck commented on a diff in pull request #28413: Route remaining prints in boot.go through logging service if possible

lostluck commented on code in PR #28413:
URL: https://github.com/apache/beam/pull/28413#discussion_r1323415469


##########
sdks/go/container/tools/buffered_logging_test.go:
##########
@@ -166,4 +167,59 @@ func TestBufferedLogger(t *testing.T) {
 			}
 		}
 	})
+
+	t.Run("direct print", func(t *testing.T) {
+		catcher := &logCatcher{}
+		l := &Logger{client: catcher}
+		bl := NewBufferedLogger(l)
+
+		bl.Printf(ctx, "foo %v", "bar")
+
+		received := catcher.msgs[0].GetLogEntries()[0]
+
+		if got, want := received.Message, "foo bar"; got != want {
+			t.Errorf("l.Printf(\"foo %%v\", \"bar\"): got message %q, want %q", got, want)
+		}
+
+		if got, want := received.Severity, fnpb.LogEntry_Severity_DEBUG; got != want {
+			t.Errorf("l.Printf(\"foo %%v\", \"bar\"): got severity %v, want %v", got, want)
+		}
+	})
+
+	t.Run("debug flush at interval", func(t *testing.T) {
+		catcher := &logCatcher{}
+		l := &Logger{client: catcher}
+		interval := time.Duration(5e9)

Review Comment:
   As a rule, don't do this. Use 5 * time.Second or similar which actually communicates the expectation correctly.



##########
sdks/go/container/tools/buffered_logging_test.go:
##########
@@ -166,4 +167,59 @@ func TestBufferedLogger(t *testing.T) {
 			}
 		}
 	})
+
+	t.Run("direct print", func(t *testing.T) {
+		catcher := &logCatcher{}
+		l := &Logger{client: catcher}
+		bl := NewBufferedLogger(l)
+
+		bl.Printf(ctx, "foo %v", "bar")
+
+		received := catcher.msgs[0].GetLogEntries()[0]
+
+		if got, want := received.Message, "foo bar"; got != want {
+			t.Errorf("l.Printf(\"foo %%v\", \"bar\"): got message %q, want %q", got, want)
+		}
+
+		if got, want := received.Severity, fnpb.LogEntry_Severity_DEBUG; got != want {
+			t.Errorf("l.Printf(\"foo %%v\", \"bar\"): got severity %v, want %v", got, want)
+		}
+	})
+
+	t.Run("debug flush at interval", func(t *testing.T) {
+		catcher := &logCatcher{}
+		l := &Logger{client: catcher}
+		interval := time.Duration(5e9)
+		bl := NewBufferedLoggerWithFlushInterval(context.Background(), l, interval)
+
+		messages := []string{"foo", "bar", "baz"}
+
+		for _, message := range messages {
+			// Pause for four seconds before each message
+			time.Sleep(2e9)

Review Comment:
   Consider adding a `now` field to the buffered logger that buffered logger uses for "now", defaulting to `time.Now` in the constructors, but can be overridden in these tests.
   
   You'll need to change away from using `time.Since` but this avoids having sleeps in the tests, allowing for fast, deterministic unit tests.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org