From 07d86cce0aa46046b41194f2543cab17c3592e2a Mon Sep 17 00:00:00 2001 From: Sitaram Kalluri Date: Mon, 16 Oct 2023 17:58:57 +0530 Subject: [PATCH] fix: Wait untill the root server is fully initialized --- .../test/check_docker_readiness.dart | 10 +++++++--- .../test/check_root_server_readiness.dart | 14 +++++++++----- tests/at_functional_test/test/check_test_env.dart | 14 ++++++++++++-- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/tests/at_functional_test/test/check_docker_readiness.dart b/tests/at_functional_test/test/check_docker_readiness.dart index c0bffe31c..c7486367d 100644 --- a/tests/at_functional_test/test/check_docker_readiness.dart +++ b/tests/at_functional_test/test/check_docker_readiness.dart @@ -16,15 +16,19 @@ void main() { test('checking for test environment readiness', () async { _secureSocket = await secure_socket_connection(rootServer, atsignPort); - print('connection established'); socket_listener(_secureSocket); String response = ''; - while (response.isEmpty || response == 'data:null\n') { + while ((retryCount < maxRetryCount) && + (response.isEmpty || response == 'data:null\n')) { _secureSocket.write('lookup:signing_publickey$atsign\n'); response = await read(); print('waiting for signing public key response : $response'); await Future.delayed(Duration(milliseconds: 100)); + if (response.startsWith('data:')) { + break; + } } await _secureSocket.close(); - }, timeout: Timeout(Duration(minutes: 1))); + expect(response.startsWith('data:'), true); + }); } diff --git a/tests/at_functional_test/test/check_root_server_readiness.dart b/tests/at_functional_test/test/check_root_server_readiness.dart index 2dfcef06a..88bd3ce28 100644 --- a/tests/at_functional_test/test/check_root_server_readiness.dart +++ b/tests/at_functional_test/test/check_root_server_readiness.dart @@ -15,6 +15,8 @@ void main() { late SecureSocket _secureSocket; + bool isRootServerStarted = false; + test('checking for root server readiness', () async { while (retryCount < maxRetryCount) { try { @@ -25,16 +27,17 @@ void main() { if (response == '@') { print('Secure Socket is open for Root Server'); } - var isRootServerStarted = - await _lookupForSecondaryAddress(_secureSocket, atSign, rootServer); + isRootServerStarted = + await _lookupForSecondaryAddress(_secureSocket, atSign, rootServer); if (isRootServerStarted) { - print('Closing socket connection'); + print('Root server started successfully'); _secureSocket.close(); break; } else { - print('Failed to start root server'); + print('Root server is not completely initialized'); _secureSocket.close(); - break; + retryCount = retryCount + 1; + await Future.delayed(Duration(seconds: 5)); } } on SocketException { print('Waiting for the root server to start: RetryCount: $retryCount'); @@ -46,6 +49,7 @@ void main() { retryCount = retryCount + 1; } } + expect(isRootServerStarted, true, reason: 'Failed to start root server successfully'); }, timeout: Timeout(Duration(minutes: 1))); } diff --git a/tests/at_functional_test/test/check_test_env.dart b/tests/at_functional_test/test/check_test_env.dart index 85e8d76f5..f07584447 100644 --- a/tests/at_functional_test/test/check_test_env.dart +++ b/tests/at_functional_test/test/check_test_env.dart @@ -9,18 +9,28 @@ void main() { var rootServer = 'vip.ve.atsign.zone'; var atsign = '@sitaramđź› '; var atsignPort = 25017; + bool arePKAMKeysLoaded = false; + int maxRetryCount = 10; + int retryCount = 1; test('checking for test environment readiness', () async { _secureSocket = await secure_socket_connection(rootServer, atsignPort); print('connection established'); socket_listener(_secureSocket); String response = ''; - while (response.isEmpty || response.startsWith('error:')) { + while ((retryCount < maxRetryCount) && + (response.isEmpty || response.startsWith('error:'))) { _secureSocket.write('lookup:pkaminstalled$atsign\n'); response = await read(); print('Waiting for PKAM keys to load : $response'); + if (response.startsWith('data:')) { + arePKAMKeysLoaded = true; + break; + } await Future.delayed(Duration(seconds: 1)); } await _secureSocket.close(); - }, timeout: Timeout(Duration(minutes: 1))); + expect(arePKAMKeysLoaded, true, + reason: 'PKAM Keys are not loaded successfully'); + }); }