Fix io tests not collecting coverage data when using run()
Before, postgrest was killed after each test and no coverage data was saved. Now the process is terminated gracefully via SIGTERM first to allow writing the .tix file.
This commit is contained in:
committed by
Remo Rechkemmer
parent
c7f0d42323
commit
568477b6af
+5
-3
@@ -184,8 +184,10 @@ let
|
||||
# temporary directory to collect data in
|
||||
tmpdir="$(mktemp -d)"
|
||||
|
||||
# we keep the tmpdir when an error occurs for debugging and only remove it on success
|
||||
trap 'echo Temporary directory kept at: $tmpdir' ERR SIGINT SIGTERM
|
||||
# we keep the tmpdir when an error occurs for debugging
|
||||
trap 'echo Temporary directory kept at: $tmpdir' ERR
|
||||
# remove the tmpdir when cancelled (postgrest-watch)
|
||||
trap 'rm -rf "$tmpdir"' SIGINT SIGTERM
|
||||
|
||||
# build once before running all the tests
|
||||
${cabal-install}/bin/cabal v2-build ${devCabalOptions} --enable-tests all
|
||||
@@ -199,7 +201,7 @@ let
|
||||
${withTmpDb postgresql} ${cabal-install}/bin/cabal v2-test ${devCabalOptions}
|
||||
|
||||
# collect all the tix files
|
||||
${ghc}/bin/hpc sum --union --exclude=Paths_postgrest --output="$tmpdir"/tests.tix "$tmpdir"/io.tix "$tmpdir"/spec.tix
|
||||
${ghc}/bin/hpc sum --union --exclude=Paths_postgrest --output="$tmpdir"/tests.tix "$tmpdir"/io*.tix "$tmpdir"/spec.tix
|
||||
|
||||
# prepare the overlay
|
||||
${ghc}/bin/hpc overlay --output="$tmpdir"/overlay.tix test/coverage.overlay
|
||||
|
||||
@@ -73,12 +73,22 @@ def defaultenv():
|
||||
}
|
||||
|
||||
|
||||
def hpctixfile():
|
||||
"Returns an individual filename for each test, if the HPCTIXFILE environment variable is set."
|
||||
if "HPCTIXFILE" not in os.environ:
|
||||
return ""
|
||||
|
||||
tixfile = pathlib.Path(os.environ["HPCTIXFILE"])
|
||||
test = hash(os.environ["PYTEST_CURRENT_TEST"])
|
||||
return tixfile.with_suffix(f".{test}.tix")
|
||||
|
||||
|
||||
def dumpconfig(configpath=None, env=None, stdin=None):
|
||||
"Dump the config as parsed by PostgREST."
|
||||
env = env or {}
|
||||
|
||||
command = [POSTGREST_BIN, "--dump-config"]
|
||||
env["HPCTIXFILE"] = os.getenv("HPCTIXFILE", "")
|
||||
env["HPCTIXFILE"] = hpctixfile()
|
||||
|
||||
if configpath:
|
||||
command.append(configpath)
|
||||
@@ -88,7 +98,7 @@ def dumpconfig(configpath=None, env=None, stdin=None):
|
||||
)
|
||||
|
||||
process.stdin.write(stdin or b"")
|
||||
result = process.communicate()[0]
|
||||
result = process.communicate(timeout=5)[0]
|
||||
process.kill()
|
||||
process.wait()
|
||||
if process.returncode != 0:
|
||||
@@ -112,7 +122,7 @@ def run(configpath=None, stdin=None, env=None, port=None):
|
||||
baseurl = "http+unix://" + urllib.parse.quote_plus(str(socketfile))
|
||||
|
||||
command = [POSTGREST_BIN]
|
||||
env["HPCTIXFILE"] = os.getenv("HPCTIXFILE", "")
|
||||
env["HPCTIXFILE"] = hpctixfile()
|
||||
|
||||
if configpath:
|
||||
command.append(configpath)
|
||||
@@ -127,8 +137,12 @@ def run(configpath=None, stdin=None, env=None, port=None):
|
||||
|
||||
yield PostgrestProcess(process=process, session=PostgrestSession(baseurl))
|
||||
finally:
|
||||
process.kill()
|
||||
process.wait()
|
||||
process.terminate()
|
||||
try:
|
||||
process.wait(timeout=1)
|
||||
except:
|
||||
process.kill()
|
||||
process.wait()
|
||||
|
||||
|
||||
def freeport():
|
||||
|
||||
Reference in New Issue
Block a user