From c413d446361d94bd70d63489dbaf077166df0729 Mon Sep 17 00:00:00 2001 From: Matthew Hambley Date: Wed, 3 Apr 2024 16:23:08 +0100 Subject: [PATCH] Turned test server into a fixture. --- .../steps/grab/test_svn_fcm_unit_test.py | 40 +++++++++---------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/tests/unit_tests/steps/grab/test_svn_fcm_unit_test.py b/tests/unit_tests/steps/grab/test_svn_fcm_unit_test.py index 05bcd27d..7e26c3eb 100644 --- a/tests/unit_tests/steps/grab/test_svn_fcm_unit_test.py +++ b/tests/unit_tests/steps/grab/test_svn_fcm_unit_test.py @@ -70,37 +70,33 @@ def test_extract_from_file(self, workspace, tmp_path: Path) -> None: file_tree_compare(workspace.tree_path, source_path) assert not (source_path / '.svn').exists() - def test_extract_from_svn(self, workspace, tmp_path: Path) -> None: - """ - Checks that a source tree can be extracted from a Subversion - repository accessed through its own protocol. - """ - command: List[str] = ['svnserve', '-r', str(workspace.repo_path), '-X'] + @fixture(scope='class') + def server(self, workspace): + command = ['svnserve', '-r', str(workspace.repo_path), '-X'] process = Popen(command) # # It seems there can be a delay between the server starting and the - # listen socket opening. Thus we have a number of retries. + # listen socket opening. Thus we have a sleep. # - # TODO: Is there a better solution such that we don't try to connect - # until the socket is open? + # Todo: Is there a better solution such that we know for certain when + # the socket is open? # + time.sleep(3.0) + yield workspace + process.wait(timeout=1) + assert process.returncode == 0 + + def test_extract_from_svn(self, server, tmp_path: Path) -> None: + """ + Checks that a source tree can be extracted from a Subversion + repository accessed through its own protocol. + """ source_path = tmp_path / 'bar' / 'source' config = BuildConfig('bar', fab_workspace=tmp_path) - for retry in range(3, 0, -1): - try: - svn_export(config, 'svn://127.0.0.1/trunk') - except FabException as ex: - if range == 0: - raise ex - time.sleep(1.0) - else: - break - file_tree_compare(workspace.tree_path, source_path) + svn_export(config, 'svn://127.0.0.1/trunk') + file_tree_compare(server.tree_path, source_path) assert not (source_path / '.svn').exists() - process.wait(timeout=1) - assert process.returncode == 0 - @mark.skip(reason="Too hard to test at the moment.") def test_extract_from_http(self, repo: Tuple[Path, Path], tmp_path: Path): """