44
55from collections .abc import Iterator
66from contextlib import contextmanager
7+ from enum import Enum
78from pathlib import Path
89import random
910import string
1819import psycopg
1920
2021TEST_CODE_PATH_VAR = 'GEOENGINE_TEST_CODE_PATH'
22+ TEST_BUILD_TYPE_VAR = 'GEOENGINE_TEST_BUILD_TYPE'
2123
2224POSTGRES_HOST = 'localhost'
2325POSTGRES_PORT = 5432
@@ -35,7 +37,12 @@ def GeoEngineTestInstance(port: Optional[int] = None) -> Iterator['GeoEngineProc
3537 if TEST_CODE_PATH_VAR not in os .environ :
3638 raise RuntimeError (f'Environment variable { TEST_CODE_PATH_VAR } not set' )
3739
38- geo_engine_binaries = GeoEngineBinaries (Path (os .environ [TEST_CODE_PATH_VAR ]))
40+ if os .environ .get ('GEOENGINE_TEST_BUILD_TYPE' , 'debug' ).lower () == 'release' :
41+ build_type = BuildType .RELEASE
42+ else :
43+ build_type = BuildType .DEBUG
44+
45+ geo_engine_binaries = GeoEngineBinaries (Path (os .environ [TEST_CODE_PATH_VAR ]), build_type )
3946
4047 try :
4148 ge = GeoEngineProcess (
@@ -49,6 +56,12 @@ def GeoEngineTestInstance(port: Optional[int] = None) -> Iterator['GeoEngineProc
4956 ge ._stop () # pylint: disable=protected-access
5057
5158
59+ class BuildType (Enum ):
60+ '''Build type of the cargo build.'''
61+ DEBUG = 'debug'
62+ RELEASE = 'release'
63+
64+
5265def get_open_port () -> int :
5366 '''Get an open port on the local machine.'''
5467 with socket .socket (socket .AF_INET , socket .SOCK_STREAM ) as s :
@@ -76,10 +89,11 @@ class GeoEngineBinaries:
7689 _lock = threading .Lock ()
7790
7891 _code_path : Path
92+ _build_type : BuildType
7993 _server_binary_path : Path
8094 _cli_binary_path : Path
8195
82- def __new__ (cls , code_path : Path ) -> 'GeoEngineBinaries' :
96+ def __new__ (cls , code_path : Path , build_type : BuildType ) -> 'GeoEngineBinaries' :
8397 '''Create Geo Engine binaries for testing.'''
8498
8599 if cls ._instance is not None :
@@ -89,6 +103,7 @@ def __new__(cls, code_path: Path) -> 'GeoEngineBinaries':
89103 if cls ._instance is None :
90104 cls ._instance = super ().__new__ (cls )
91105 cls ._instance ._code_path = code_path
106+ cls ._instance ._build_type = build_type
92107
93108 cls ._instance ._build_geo_engine ()
94109
@@ -102,21 +117,21 @@ def _build_geo_engine(self) -> None:
102117 if cargo_bin is None :
103118 raise RuntimeError ('Cargo not found' )
104119
105- logging .info ("Building Geo Engine binaries… this may take a while." )
120+ logging .info ("Building Geo Engine binaries in %s mode … this may take a while." , self . _build_type . value )
106121
107122 subprocess .run (
108123 [
109124 cargo_bin ,
110125 'build' ,
111126 '--locked' ,
112127 '--bins' ,
113- ],
128+ ] + ([ '--release' ] if self . _build_type == BuildType . RELEASE else []) ,
114129 check = True ,
115130 cwd = self ._code_path ,
116131 )
117132
118133 self ._server_binary_path = self ._code_path / 'target/debug/geoengine-server'
119- self ._cli_binary_path = self ._code_path / 'target/debug/ geoengine-cli'
134+ self ._cli_binary_path = self ._code_path / 'target' / self . _build_type . value / ' geoengine-cli'
120135
121136 if not self ._server_binary_path .exists ():
122137 raise RuntimeError (f'Server binary not found at { self ._server_binary_path } ' )
0 commit comments