Wednesday, 15 May 2013

Does go test run unit tests concurrently? -



Does go test run unit tests concurrently? -

when go test ran runs files ending in _test.go running functions start in format testxxx , utilize (*t testing.t) module. wondering if each function in _test.go file ran concurrently or if definitively ran each function separately? create go routine each one? if create go routine each one, can monitor go routines in way? ever possible golibrary.goroutines() , instance each 1 , monitor them how or that?

note: question assumes using testing framework comes go (testing).

yes, tests executed goroutines and, thus, executed concurrently.

however, tests not run in parallel default pointed out @jacobsa. enable parallel execution have phone call t.parallel() in test case , set gomaxprocs appropriately or supply -parallel n.

the simplest solution case when running tests in parallel have global piece port numbers , global atomically incremented index serves association between test , port slice. way command port numbers , have 1 port each test. example:

import "sync/atomic" var ports [...]uint64 = {10, 5, 55} var portindex uint32 func nextport() uint32 { homecoming atomic.adduint32(&portindex, 1) }

unit-testing go

No comments:

Post a Comment