Files
ResInsight/GrpcInterface/Python/rips/tests/test_launch.py
Kristian Bendiksen c2b5ab8d2c #9307 Python: avoid assigning same port number to multiple grpc sessions
* Python: avoid assigning same port number to multiple grpc sessions
* Add retry count when checking for port number file
* Use grpc to find and use port number
* Add test used to start several instances of resinsight at the same time
Testing up to 50 instances works well

* Python: allow launch_port == 0 to assign port by GRPC in Instance.launch().
Also allow longer wait before failing the port number file reading:
it can take some time to launch when launching lots of instances at
the same time.
2022-09-26 14:19:21 +02:00

52 lines
1.1 KiB
Python

import sys
import os
import math
import pytest
import grpc
import tempfile
import time
import multiprocessing
sys.path.insert(1, os.path.join(sys.path[0], "../../"))
import rips
import dataroot
def launch_resinsight(sec=1):
instance = rips.Instance.launch(console=True, launch_port=0)
print(instance.location)
print(f"Sleeping for {sec} second(s): ", instance.location)
time.sleep(sec)
print(f"Done sleeping", instance.location)
instance.exit()
def test_launch_sequential(rips_instance, initialize_test):
instance_list = []
for i in range(4):
rips_instance = rips.Instance.launch(console=True)
instance_list.append(rips_instance)
for instance in instance_list:
print(instance)
instance.exit()
def test_launch_parallell(rips_instance, initialize_test):
process_list = []
instance_count = 10
for i in range(instance_count):
process = multiprocessing.Process(target=launch_resinsight)
process_list.append(process)
for process in process_list:
process.start()
# completing process
for p in process_list:
p.join()