Exemple #1
0
def xtest_exit():
    with patch('sys.exit') as exit_mock:
        def doExit(a):
            status['exit'] = True

        def invokeExit():
            algorunner._exit(None)

        def isServingTrue():
            return True

        def isServingFalse():
            return False

        algorunner = Algorunner()
        algorunner.loadAlgorithmCallbacks(startCallback)
        algorunner.connectToWorker(config)
        sleep(1)
        status = {'exit': False}
        algorunner.loadAlgorithmCallbacks(startCallback, exit=doExit)
        algorunner._dataServer.isServing = isServingTrue
        Thread(target=invokeExit).start()
        sleep(1)
        assert status['exit'] == False
        algorunner._dataServer.isServing = isServingFalse
        sleep(1)
        assert status['exit'] == True
        assert exit_mock.called
Exemple #2
0
def test_connect_to_worker():
    config.discovery.update({"port": "9021"})
    algorunner = Algorunner()
    algorunner.loadAlgorithmCallbacks(startCallback2, options=config)
    algorunner.connectToWorker(config)
    time.sleep(2)
    assert algorunner._connected == True
    assert algorunner._input == mockdata.initData
    algorunner.close()
Exemple #3
0
def main():
    print("starting algorithm runner")
    conf = config.Config
    alg = Algorunner()
    alg.loadAlgorithm(conf.algorithm)
    job = alg.connectToWorker(conf.socket)
    job.join()
Exemple #4
0
def test_callback():
    sm = StorageManager(config.storage)
    algorunner = Algorunner()

    algorunner.loadAlgorithmCallbacks(start, options=config)
    algorunner.connectToWorker(config)
    origGet = algorunner._dataAdapter.tryGetDataFromPeerOrStorage
    def mockStorageGet(response):
        return storageMock.get(response.get('storageInfo').get('path'))
    algorunner._dataAdapter.tryGetDataFromPeerOrStorage = mockStorageGet
    time.sleep(3)
    (header, payload) = sm.storage.get({"path": "local-hkube/jobId/taskId"})
    algorunner._dataAdapter.tryGetDataFromPeerOrStorage = origGet
    decoded = encoding.decode(header=header, value=payload)
    assert decoded[0][0] == inp1
    assert decoded[1] == outp2
    time.sleep(2)
    Tracer.instance.close()
    algorunner.close()
Exemple #5
0
def main():
    print("starting algorithm runner")
    alg = Algorunner()
    alg.loadAlgorithmCallbacks(algorithm.start)
    job = alg.connectToWorker(Config.socket)
    job.join()
Exemple #6
0
def main():
    alg = Algorunner()
    alg.loadAlgorithmCallbacks(start)
    job = alg.connectToWorker(socket)
    job.join()