@@ -13,6 +13,7 @@ import {
1313 getGitProjectRoot ,
1414 installChaosMeshChart ,
1515 setupEnvironment ,
16+ startPortForward ,
1617 startPortForwardForEthereum ,
1718 startPortForwardForRPC ,
1819} from './utils.js' ;
@@ -107,4 +108,133 @@ describe('smoke test', () => {
107108 logger,
108109 } ) ;
109110 } ) ;
111+
112+ it ( 'can establish all port forwards used by spartan tests' , async ( ) => {
113+ // This test validates all the port forwarding mechanisms used across the spartan test suite.
114+ // It helps build confidence that the K8s infrastructure is accessible before running more complex tests.
115+
116+ const testForwardProcesses : ChildProcess [ ] = [ ] ;
117+ const RETRY_TIMEOUT_SECONDS = 60 * 60 ; // 1 hour
118+ const RETRY_INTERVAL_SECONDS = 12 ;
119+
120+ try {
121+ logger . info ( 'Testing all port forwards...' ) ;
122+
123+ const [ rpcResult , ethResult , promResult , adminResult ] = await Promise . all ( [
124+ // Test RPC port forward
125+ retryUntil (
126+ async ( ) => {
127+ try {
128+ const { process : rpcProcess , port : rpcPort } = await startPortForwardForRPC ( config . NAMESPACE ) ;
129+ const rpcUrl = `http://127.0.0.1:${ rpcPort } ` ;
130+ const testNode = createAztecNodeClient ( rpcUrl ) ;
131+ const nodeInfo = await testNode . getNodeInfo ( ) ;
132+ if ( nodeInfo ?. enr ?. startsWith ( 'enr:-' ) ) {
133+ return { process : rpcProcess , port : rpcPort } ;
134+ }
135+ rpcProcess . kill ( ) ;
136+ return undefined ;
137+ } catch {
138+ return undefined ;
139+ }
140+ } ,
141+ 'RPC port forward' ,
142+ RETRY_TIMEOUT_SECONDS ,
143+ RETRY_INTERVAL_SECONDS ,
144+ ) ,
145+
146+ // Test Ethereum port forward
147+ retryUntil (
148+ async ( ) => {
149+ try {
150+ const { process : ethProcess , port : ethPort } = await startPortForwardForEthereum ( config . NAMESPACE ) ;
151+ const ethUrl = `http://127.0.0.1:${ ethPort } ` ;
152+ const testEthClient = createPublicClient ( { transport : http ( ethUrl ) } ) ;
153+ const blockNumber = await testEthClient . getBlockNumber ( ) ;
154+ if ( blockNumber >= 0n ) {
155+ return { process : ethProcess , port : ethPort , blockNumber } ;
156+ }
157+ ethProcess . kill ( ) ;
158+ return undefined ;
159+ } catch {
160+ return undefined ;
161+ }
162+ } ,
163+ 'Ethereum port forward' ,
164+ RETRY_TIMEOUT_SECONDS ,
165+ RETRY_INTERVAL_SECONDS ,
166+ ) ,
167+
168+ // Test Prometheus port forward
169+ retryUntil (
170+ async ( ) => {
171+ // Try metrics namespace first
172+ try {
173+ const result = await startPortForward ( {
174+ resource : `svc/metrics-prometheus-server` ,
175+ namespace : 'metrics' ,
176+ containerPort : 80 ,
177+ } ) ;
178+ return { ...result , namespace : 'metrics' } ;
179+ } catch {
180+ // Fall back to test namespace
181+ try {
182+ const result = await startPortForward ( {
183+ resource : `svc/prometheus-server` ,
184+ namespace : config . NAMESPACE ,
185+ containerPort : 80 ,
186+ } ) ;
187+ return { ...result , namespace : config . NAMESPACE } ;
188+ } catch {
189+ return undefined ;
190+ }
191+ }
192+ } ,
193+ 'Prometheus port forward' ,
194+ RETRY_TIMEOUT_SECONDS ,
195+ RETRY_INTERVAL_SECONDS ,
196+ ) ,
197+
198+ // Test validator admin port forward
199+ retryUntil (
200+ async ( ) => {
201+ try {
202+ const result = await startPortForward ( {
203+ resource : `pod/${ config . NAMESPACE } -validator-aztec-node-0` ,
204+ namespace : config . NAMESPACE ,
205+ containerPort : 8880 ,
206+ } ) ;
207+ return result ;
208+ } catch {
209+ return undefined ;
210+ }
211+ } ,
212+ 'Validator admin port forward' ,
213+ RETRY_TIMEOUT_SECONDS ,
214+ RETRY_INTERVAL_SECONDS ,
215+ ) ,
216+ ] ) ;
217+
218+ testForwardProcesses . push ( rpcResult . process , ethResult . process , promResult . process , adminResult . process ) ;
219+
220+ expect ( rpcResult . port ) . toBeGreaterThan ( 0 ) ;
221+ logger . info ( `RPC port forward OK on port ${ rpcResult . port } ` ) ;
222+
223+ expect ( ethResult . port ) . toBeGreaterThan ( 0 ) ;
224+ logger . info ( `Ethereum port forward OK on port ${ ethResult . port } , block number: ${ ethResult . blockNumber } ` ) ;
225+
226+ expect ( promResult . port ) . toBeGreaterThan ( 0 ) ;
227+ logger . info ( `Prometheus port forward OK on port ${ promResult . port } (${ promResult . namespace } namespace)` ) ;
228+
229+ expect ( adminResult . port ) . toBeGreaterThan ( 0 ) ;
230+ logger . info ( `Validator admin port forward OK on port ${ adminResult . port } ` ) ;
231+
232+ logger . info ( 'All port forward checks completed successfully' ) ;
233+ } finally {
234+ // Clean up all test port forwards
235+ for ( const proc of testForwardProcesses ) {
236+ proc . kill ( ) ;
237+ }
238+ }
239+ } ) ;
110240} ) ;
0 commit comments