gotestsum icon indicating copy to clipboard operation
gotestsum copied to clipboard

Add option for max output when generating unit reports

Open sodul opened this issue 5 years ago • 1 comments

We do have some tests that generate a lot of output, for example we have a json output that is close to 1GB in one of our more complex test suites. We will work with the test owners to log to a separate log file that can be stored separately since that is definitely too much, but we would love to have an option to trim the test output if it grows too large. We can always refer back to the json file if need be since we are compressing it and keeping it around for a while as part of our CI pipelines.

Sample test code:

	for i := 1; i <= 10000000; i++ {
		fmt.Printf("i: %d long test output for sizing.\n", i)
	}
	require.Nil(t, 1)

This will generate a 1.5GB json (not for gotestsum to address) which we can use to look at the log and a 419MB junit xml.

Having the ability to set a max test output would allow to save some RAM (don't keep the entire buffer, just the first few kb or lines) while running the tests, and save some resources on whatever would post-process the unit reports.

For those that do need to get the test output in case of a failure a fallback on the json file with all the line is always possible.

Instead of simply trimming you could keep the heading lines and trailing lines of the test output:

i: 0 long test output for sizing.
i: 1 long test output for sizing.
i: 2 long test output for sizing.
i: 3 long test output for sizing.
i: 4 long test output for sizing.
i: 5 long test output for sizing.
i: 6 long test output for sizing.
i: 7 long test output for sizing.
i: 8 long test output for sizing.
i: 9 long test output for sizing.
i: 10 long test output for sizing.
[ ... snipped 9999990 lines from test output due to large size ... ]
i: 9999991 long test output for sizing.
i: 9999992 long test output for sizing.
i: 9999993 long test output for sizing.
i: 9999994 long test output for sizing.
i: 9999995 long test output for sizing.
i: 9999996 long test output for sizing.
i: 9999997 long test output for sizing.
i: 9999998 long test output for sizing.
i: 9999999 long test output for sizing.
i: 10000000 long test output for sizing.

sodul avatar Jul 02 '20 02:07 sodul

Thank you for opening this issue! I think it would make sense to limit the size of buffered output. This TODO has been around since the very first iteration of gotestsum: https://github.com/gotestyourself/gotestsum/tree/v0.5.1/testjson/execution.go#L164-L166.

dnephin avatar Jul 03 '20 23:07 dnephin