2828 rules as pex_rules ,
2929)
3030from pants .core .goals .test import TestExtraEnv
31+ from pants .engine .env_vars import EnvironmentVars
3132from pants .engine .fs import CreateDigest , Digest , FileContent
3233from pants .engine .rules import collect_rules , Get , MultiGet , rule
3334from pants .engine .process import FallibleProcessResult , ProcessCacheScope
@@ -54,16 +55,29 @@ class UsesRedisRequest:
5455
5556 # These config opts for integration tests are in:
5657 # conf/st2.dev.conf (copied to conf/st2.ci.conf)
57- # TODO: for int tests: set url by either modifying st2.{dev,ci}.conf on the fly or via env vars.
58-
59- # with our version of oslo.config (newer are slower) we can't directly override opts w/ environment variables .
58+ # These can also be updated via the ST2TESTS_REDIS_* env vars.
59+ # Integration tests should pass these changes onto subprocesses using the
60+ # ST2_COORDINATION__* env vars (which oslo_config reads) .
6061
6162 host : str = "127.0.0.1"
62- port : str = " 6379"
63+ port : int = 6379
6364
6465 @property
6566 def coord_url (self ) -> str :
66- return f"redis://{ self .host } :{ self .port } "
67+ return f"redis://{ self .host } :{ self .port } ?namespace=_st2_test"
68+
69+ @classmethod
70+ def from_env (cls , env : EnvironmentVars ) -> UsesRedisRequest :
71+ default = cls ()
72+ host = env .get ("ST2TESTS_REDIS_HOST" , default .host )
73+ port_raw = env .get ("ST2TESTS_REDIS_PORT" , str (default .port ))
74+
75+ try :
76+ port = int (port_raw )
77+ except (TypeError , ValueError ):
78+ port = default .port
79+
80+ return cls (host = host , port = port )
6781
6882
6983@dataclass (frozen = True )
@@ -88,11 +102,8 @@ async def redis_is_running_for_pytest(
88102 request : PytestUsesRedisRequest ,
89103 test_extra_env : TestExtraEnv ,
90104) -> PytestPluginSetup :
91- redis_host = test_extra_env .env .get ("ST2TESTS_REDIS_HOST" , "127.0.0.1" )
92- redis_port = test_extra_env .env .get ("ST2TESTS_REDIS_PORT" , "6379" )
93-
94105 # this will raise an error if redis is not running
95- _ = await Get (RedisIsRunning , UsesRedisRequest ( host = redis_host , port = redis_port ))
106+ _ = await Get (RedisIsRunning , UsesRedisRequest . from_env ( env = test_extra_env . env ))
96107
97108 return PytestPluginSetup ()
98109
@@ -161,7 +172,7 @@ async def redis_is_running(
161172 not_installed_clause_deb = "this is one way to install it:" ,
162173 install_instructions_deb = dedent (
163174 """\
164- sudo apt-get install -y mongodb redis
175+ sudo apt-get install -y redis
165176 # Don't forget to start redis.
166177 """
167178 ),
@@ -170,7 +181,8 @@ async def redis_is_running(
170181 """\
171182 You can also export the ST2TESTS_REDIS_HOST and ST2TESTS_REDIS_PORT
172183 env vars to automatically use any redis host, local or remote,
173- while running unit and integration tests.
184+ while running unit and integration tests. Tests do not use any
185+ ST2_COORDINATION__* vars at this point.
174186 """
175187 ),
176188 ),
0 commit comments