One way around the flag problem is to accept an interface, instead of using testing.T.
Watch Mitchell Hashimoto's talk from GopherCon from about 39m30s: https://youtu.be/8hQG7QlcLBk?t=2368 http://github.com/mitchellh/go-testing-interface On Mon, Jul 24, 2017 at 1:44 AM, roger peppe <rogpe...@gmail.com> wrote: > > > On 24 July 2017 at 09:12, Howard Guo <guohou...@gmail.com> wrote: > >> Thanks Nigel! I should definitely consider improving the test case. >> >> Go compiler appears to automatically places test flags into executable >> whenever "testing" package is included - no matter the function using >> "testing" package is dead code or otherwise. So here's a bug report for go: >> https://github.com/golang/go/issues/21141 >> > > Although this could be considered a bug, it's not one that can be fixed, > because people rely on this behaviour of the testing package. > > Consider it a warning not to include testing dependencies in production > code. > > >> >> Kind regards, >> Howard >> >> On Sunday, 23 July 2017 06:54:28 UTC+2, Nigel Tao wrote: >>> >>> On Sat, Jul 22, 2017 at 7:08 PM, Howard Guo <guoh...@gmail.com> wrote: >>> > https://github.com/HouzuoGuo/laitos >>> >>> It's tangential to your question, but out of curiousity, I skimmed the >>> source code. In things like func TestUDPServer in >>> https://github.com/HouzuoGuo/laitos/blob/master/frontend/plain/udp.go, >>> you say: >>> >>> var stoppedNormally bool >>> go func() { >>> etc >>> stoppedNormally = true >>> }() >>> etc >>> server.Stop() >>> time.Sleep(1 * time.Second) >>> if !stoppedNormally { etc } >>> >>> This is an example of incorrect synchronization as per >>> https://golang.org/ref/mem#tmp_10 >>> >>> There may be other such races in your code. I didn't do an exhaustive >>> review. It may be worthwhile to run your test suite under the race >>> detector. >>> >> -- >> You received this message because you are subscribed to the Google Groups >> "golang-nuts" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to golang-nuts+unsubscr...@googlegroups.com. >> For more options, visit https://groups.google.com/d/optout. >> > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.