import json
import os
import time
import tempfile
from threading import Thread

import torii_tests
from torii import Torii

APP_DIR = os.path.dirname(torii_tests.__file__) + '/resources/applications'

if __name__ == '__main__':

    base_url = 'https://10.140.9.172:8443/torii'
    nb_tasks = 1000

    t = Torii(base_url=base_url, username='hpcgadmin', password='hpcgadmin')

    # get the application
    app = t.applications.import_application(path=os.path.join(APP_DIR, 'dir', 'test_app_relay_bench'), force=True)


    # initiate a new task
    task = t.tasks.new(name='test json input', description='task with json input', application=app)

    task.set_input('nb_procs', 1)
    task.set_input('timeout', 20)

    # submit the new task
    task.submit()

    # wait for the task to finish
    assert task.wait()

    print(json.dumps(task.to_json(), indent=4))



