github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-core-master/integration/sawtooth_integration/tests/test_workload.py (about) 1 # Copyright 2017 Intel Corporation 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 # ------------------------------------------------------------------------------ 15 16 import unittest 17 import time 18 import logging 19 import subprocess 20 import shlex 21 22 from sawtooth_integration.tests.integration_tools import wait_for_rest_apis 23 from sawtooth_cli.rest_client import RestClient 24 25 26 LOGGER = logging.getLogger(__name__) 27 LOGGER.setLevel(logging.INFO) 28 29 30 # the appropriateness of these parameters depends on 31 # the rate at which blocks are published 32 WORKLOAD_TIME = 5 33 MINIMUM_BLOCK_COUNT = 3 34 35 36 class TestWorkload(unittest.TestCase): 37 @classmethod 38 def setUpClass(cls): 39 url = 'rest-api:8008' 40 wait_for_rest_apis([url]) 41 http = 'http://' + url 42 cls.client = RestClient(http) 43 cls.client.url = http 44 45 def test_workload(self): 46 workload_process = subprocess.Popen(shlex.split( 47 'intkey workload -u {}'.format( 48 self.client.url))) 49 50 # run workload for WORKLOAD_TIME seconds 51 time.sleep(WORKLOAD_TIME) 52 53 subprocess.run(shlex.split( 54 'sawtooth block list --url {}'.format(self.client.url))) 55 56 blocks = self.client.list_blocks() 57 58 # if workload is working, expect at least 59 # MINIMUM_BLOCK_COUNT blocks to have been created 60 self.assertGreaterEqual( 61 len(list(blocks)), 62 MINIMUM_BLOCK_COUNT, 63 'Not enough blocks; something is probably wrong with workload') 64 65 workload_process.terminate()