Test schedule class and utilities for running a test in compressed time.

Constructors

Properties

logger: Logger

Methods

  • Private

    Parameters

    • key: string

    Returns Promise<{
        key: string;
        startTime: Date;
        lastTestTime: Date;
    }>

  • A convenience method for reseting all event models except the test schedule.

    Returns Promise<void>

  • Gets a point-in-time within a simulated test period as part of a repeating test.

    You can use it to help simulate election events by requesting results at points in time during the event.

    When you first request a test time, the client will save an initial datetime in the database and calculate consecutive test periods from that point in time compressed to the specified duration for the test.

    An example:

    Say you want to simulate a test period from noon to midnight on a particular day and compress that to run within an hour. When you first request a test time using a new test key, It then will return a test time representing noon. If you request a test time 15 minutes later, it will return a test time around 3 p.m., about a quarter through the test period. 15 minutes later again and It then will return a test time of 6 p.m., and so on. After the first hour, the test period will start again and return a test time of noon.

    Parameters

    • key: string

      A key to identify the test schedule

    • testPeriodStart: Date

      Start datetime of the test period

    • testPeriodEnd: Date

      End datetime of the test period

    • testDuration: number = 60

      Duration to compress the test period into in minutes

    Returns Promise<{
        date: Date;
        maxDateTime: string;
        resetEvent: boolean;
    }>

    Example

    const key = 'my-test';
    const testPeriodStart = new Date('2020-11-03T12:00-05:00');
    const testPeriodEnd = new Date('2020-11-04T04:00-05:00');
    const testDuration = 60; // 60 minutes

    const testTime = await client.test.getTestTime(key, testPeriodStart, testPeriodEnd, testDuration);

    You can use the returned values to set the maxDateTime filter when updating election results.

    Example

    await client.setupEvent();

    // A hypothetical infinite test loop...
    while(true) {
    const testTime = await client.test.getTestTime(key, testPeriodStart, testPeriodEnd, testDuration);

    client.filter({
    maxDateTime: testTime.maxDateTime,
    });

    await client.getCountyVotes();

    // A simple 5-minute delay between steps...
    await Promise((resolve) => setTimeout(resolve, 5 * 60 * 1000));
    };

    Note: When a simulated test rolls over to the beginning of the test period, this method will clear all event models. You should use the returned resetEvent property to signal when you should call ElectionTonightClient.setupEvent to re-initialise the event models before calling other client methods or directly querying the database.

    Example

    const { resetEvent } = await client.test.getTestTime(key, testPeriodStart, testPeriodEnd, testDuration);

    if (resetEvent) await client.setupEvent();

    // Now call other client methods...

Generated using TypeDoc