#!/usr/bin/env python3
#
# Determine the duration of a specified test.
#
#
# TODO: This is a bare-bones, unreliable implementation that should be
# used only for testing.
#

import datetime
import sys

import pscheduler

json = pscheduler.json_load(exit_on_error=True)['spec']

# TODO: Make sure the type is one we like
# TODO: Validate the spec


try:
    timeout = json['timeout']
except KeyError:
    # If no default but there's a dawdle, double that.
    try:
        delta = pscheduler.iso8601_as_timedelta(json['dawdle']) * 2
        timeout = pscheduler.timedelta_as_iso8601(delta)
    except KeyError:
        timeout = 'PT5S'

pscheduler.succeed_json({
        "duration": timeout
})
