Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4772588

Browse files
Merge pull request#167 from dmitry-lipetsk/D20241224_001--node_start
Node.start is refactored [Victoria Shepard' ideas are used,#149]
2 parents93d1122 +00fd925 commit4772588

File tree

2 files changed

+63
-39
lines changed

2 files changed

+63
-39
lines changed

‎testgres/node.py

Lines changed: 62 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -790,48 +790,72 @@ def start(self, params=[], wait=True):
790790
"-w"ifwaitelse'-W',# --wait or --no-wait
791791
"start"]+params# yapf: disable
792792

793-
log_files0=self._collect_log_files()
794-
asserttype(log_files0)==dict# noqa: E721
793+
defLOCAL__start_node():
794+
_,_,error=execute_utility(_params,self.utils_log_file,verbose=True)
795+
asserttype(error)==str# noqa: E721
796+
iferrorand'does not exist'inerror:
797+
raiseException(error)
795798

796-
nAttempt=0
797-
timeout=1
798-
whileTrue:
799-
assertnAttempt>=0
800-
assertnAttempt<__class__._C_MAX_START_ATEMPTS
801-
nAttempt+=1
799+
defLOCAL__raise_cannot_start_node(from_exception,msg):
800+
assertisinstance(from_exception,Exception)
801+
asserttype(msg)==str# noqa: E721
802+
files=self._collect_special_files()
803+
raise_from(StartNodeException(msg,files),from_exception)
804+
805+
defLOCAL__raise_cannot_start_node__std(from_exception):
806+
assertisinstance(from_exception,Exception)
807+
LOCAL__raise_cannot_start_node(from_exception,'Cannot start node')
808+
809+
ifnotself._should_free_port:
802810
try:
803-
exit_status,out,error=execute_utility(_params,self.utils_log_file,verbose=True)
804-
iferrorand'does not exist'inerror:
805-
raiseException
811+
LOCAL__start_node()
806812
exceptExceptionase:
807-
assertnAttempt>0
808-
assertnAttempt<=__class__._C_MAX_START_ATEMPTS
809-
ifself._should_free_portandnAttempt<__class__._C_MAX_START_ATEMPTS:
813+
LOCAL__raise_cannot_start_node__std(e)
814+
else:
815+
assertself._should_free_port
816+
assert__class__._C_MAX_START_ATEMPTS>1
817+
818+
log_files0=self._collect_log_files()
819+
asserttype(log_files0)==dict# noqa: E721
820+
821+
nAttempt=0
822+
timeout=1
823+
whileTrue:
824+
assertnAttempt>=0
825+
assertnAttempt<__class__._C_MAX_START_ATEMPTS
826+
nAttempt+=1
827+
try:
828+
LOCAL__start_node()
829+
exceptExceptionase:
830+
assertnAttempt>0
831+
assertnAttempt<=__class__._C_MAX_START_ATEMPTS
832+
ifnAttempt==__class__._C_MAX_START_ATEMPTS:
833+
logging.error("Reached maximum retry attempts. Unable to start node.")
834+
LOCAL__raise_cannot_start_node(e,"Cannot start node after multiple attempts")
835+
810836
log_files1=self._collect_log_files()
811-
ifself._detect_port_conflict(log_files0,log_files1):
812-
log_files0=log_files1
813-
logging.warning(
814-
"Detected an issue with connecting to port {0}. "
815-
"Trying another port after a {1}-second sleep...".format(self.port,timeout)
816-
)
817-
time.sleep(timeout)
818-
timeout=min(2*timeout,5)
819-
cur_port=self.port
820-
new_port=utils.reserve_port()# can raise
821-
try:
822-
options= {'port':str(new_port)}
823-
self.set_auto_conf(options)
824-
except:# noqa: E722
825-
utils.release_port(new_port)
826-
raise
827-
self.port=new_port
828-
utils.release_port(cur_port)
829-
continue
830-
831-
msg='Cannot start node'
832-
files=self._collect_special_files()
833-
raise_from(StartNodeException(msg,files),e)
834-
break
837+
ifnotself._detect_port_conflict(log_files0,log_files1):
838+
LOCAL__raise_cannot_start_node__std(e)
839+
840+
log_files0=log_files1
841+
logging.warning(
842+
"Detected a conflict with using the port {0}. "
843+
"Trying another port after a {1}-second sleep...".format(self.port,timeout)
844+
)
845+
time.sleep(timeout)
846+
timeout=min(2*timeout,5)
847+
cur_port=self.port
848+
new_port=utils.reserve_port()# can raise
849+
try:
850+
options= {'port':str(new_port)}
851+
self.set_auto_conf(options)
852+
except:# noqa: E722
853+
utils.release_port(new_port)
854+
raise
855+
self.port=new_port
856+
utils.release_port(cur_port)
857+
continue
858+
break
835859
self._maybe_start_logger()
836860
self.is_started=True
837861
returnself

‎tests/test_simple.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,7 @@ def test_port_conflict(self):
12191219
withself.assertRaises(StartNodeException)asctx:
12201220
node2.init().start()
12211221

1222-
self.assertIn("Cannot start node",str(ctx.exception))
1222+
self.assertIn("Cannot start node after multiple attempts",str(ctx.exception))
12231223

12241224
self.assertEqual(node2.port,node1.port)
12251225
self.assertTrue(node2._should_free_port)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp