Skip to content

Commit

Permalink
Update wait for final state (#194) (#196)
Browse files Browse the repository at this point in the history
* update wait for final state

* add test case and reno
  • Loading branch information
kt474 authored Mar 7, 2022
1 parent 4e37df5 commit 90acbbb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion qiskit_ibm_runtime/runtime_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ def wait_for_final_state(self, timeout: Optional[float] = None) -> None:
"""
if self._status not in JOB_FINAL_STATES and not self._is_streaming():
self._ws_client_future = self._executor.submit(self._start_websocket_client)
self._ws_client_future.result(timeout)
if self._is_streaming():
self._ws_client_future.result(timeout)
self.status()

def stream_results(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
fixes:
- |
Fixed a bug where :meth:`qiskit_ibm_runtime.RuntimeJob.wait_for_final_state`
would result in a NoneType error if the job already completed and
:meth:`qiskit_ibm_runtime.RuntimeJob.status` was called beforehand.
12 changes: 11 additions & 1 deletion test/integration/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import random
import time

from qiskit.providers.jobstatus import JobStatus
from qiskit.providers.jobstatus import JOB_FINAL_STATES, JobStatus
from qiskit.test.decorators import slow_test

from qiskit_ibm_runtime.constants import API_TO_JOB_ERROR_MESSAGE
Expand Down Expand Up @@ -220,6 +220,16 @@ def test_wait_for_final_state(self, service):
job.wait_for_final_state()
self.assertEqual(JobStatus.DONE, job.status())

@run_integration_test
def test_wait_for_final_state_after_job_status(self, service):
"""Test wait for final state on a completed job when the status is updated first."""
job = self._run_program(service)
status = job.status()
while status not in JOB_FINAL_STATES:
status = job.status()
job.wait_for_final_state()
self.assertEqual(JobStatus.DONE, job.status())

@run_integration_test
def test_job_creation_date(self, service):
"""Test job creation date."""
Expand Down

0 comments on commit 90acbbb

Please sign in to comment.