Skip to content

Commit

Permalink
fix(p4): add disconnect before any connect
Browse files Browse the repository at this point in the history
It seems that an expired session might still return True for p4.connected()
  • Loading branch information
k-dovgan authored Jul 22, 2020
1 parent dccce1b commit bf85ceb
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions universum/modules/vcs/perforce_vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,28 +89,26 @@ def __init__(self, *args, **kwargs):
@make_block("Connecting")
@catch_p4exception()
def connect(self):
if not self.p4.connected():
self.p4.port = self.settings.port
self.p4.user = self.settings.user
self.p4.password = self.settings.password
self.disconnect()
self.p4.port = self.settings.port
self.p4.user = self.settings.user
self.p4.password = self.settings.password

self.p4.connect()
self.append_repo_status("Perforce server: " + self.settings.port + "\n\n")
self.p4.connect()
self.append_repo_status("Perforce server: " + self.settings.port + "\n\n")

@make_block("Disconnecting")
def disconnect(self):
with warnings.catch_warnings(record=True) as w:
self.p4.disconnect()
if not w:
return
if "Not connected" in str(w[0].message):
text = "Perforce client is not connected on disconnect. Something must have gone wrong"
self.structure.fail_current_block(text)
else:
text = ""
for line in w:
text += "\n" + warnings.formatwarning(line.message, line.category, line.filename, line.lineno)
self.structure.fail_current_block("Unexpected warning(s): " + text)
if "Not connected" in str(w[0].message): # We consider it ok for a session to expire or not be created yet
return
text = ""
for line in w:
text += "\n" + warnings.formatwarning(line.message, line.category, line.filename, line.lineno)
self.structure.fail_current_block("Unexpected warning(s): " + text)
raise SilentAbortException()

def finalize(self):
Expand Down

0 comments on commit bf85ceb

Please sign in to comment.