Exemple #1
0
void tst_schedulBatchAndWait()
{
    GLOBAL_COUNTER = 0;
    WorkQueue queue;

    const int COUNT = 5;

    std::vector<shared_ptr<WorkQueue::Job> > jobs;

    // Schedule a couple of jobs..
    for (int i=0; i<COUNT; ++i) {
        jobs.push_back(shared_ptr<WorkQueue::Job>(new OneJob(i)));
        queue.schedule(jobs.back());
    }

    // Wait for the very last one...
    jobs.back()->waitForCompletion();

    for (int i=0; i<COUNT; ++i) {
        OneJob *j = static_cast<OneJob *>(jobs.at(i).get());

        // Job should have completed.
        check_true(j->hasCompleted());

        // This will guarantee that the jobs have been completed in the right
        // order..
        check_equal(j->runId, j->jobId);
    }

    cout << __FUNCTION__ << ": ok" << endl;
}
Exemple #2
0
void tst_runOneJob()
{
    GLOBAL_COUNTER = 1;

    WorkQueue queue;
    shared_ptr<WorkQueue::Job> job(new OneJob(1));

    check_true(!job->hasCompleted());
    check_equal(static_cast<OneJob *>(job.get())->runId, -1);

    queue.schedule(job);

    // Spin a while loop, waiting 1 ms at a time, to see if the job completes
    // on its own. If we're still spinning after 10000 iterations, emit a warning
    // that the thing is probably locked up
    int counter = 0;
    while (!job->hasCompleted()) {
        this_thread::sleep_for(std::chrono::milliseconds(1));
        ++counter;
        if (counter > 10000) {
            cout << __FUNCTION__ << ": has with all likelyhood timed out, assuming failure!" << endl;
            check_true(false);
        }
    }

    if (counter == 0) {
        cout << " - job seems to have completed without any delay.. This is suspicious.." << endl;
        return;
    }

    // The runId should be the one we set up above, namely 1, as this is the
    // only job executing at present.
    check_equal(static_cast<OneJob *>(job.get())->runId, 1);

    cout << __FUNCTION__ << ": ok" << endl;
}