FOSSology  4.7.1
Open Source License Compliance by Open Source Software
testJob.c File Reference

Unit test for job operations. More...

#include <testRun.h>
#include <agent.h>
#include <scheduler.h>
#include <job.h>
#include <utils.h>
#include <string.h>
Include dependency graph for testJob.c:

Go to the source code of this file.

Macros

#define STRESS_USERS   15
 
#define STRESS_UPLOADS   20
 
#define STRESS_N_JOBS   (STRESS_USERS * STRESS_UPLOADS)
 
#define STRESS_BASE_ID   50000
 

Functions

int Prepare_Testing_Data_Job (scheduler_t *scheduler)
 
void test_job_event ()
 Test for job events. More...
 
void test_job_fun ()
 Test for job functions. More...
 
void test_scheduler_high_load_no_false_stale (void)
 Jobs blocked at max_run must not be reaped as stale. More...
 
void test_scheduler_priority_order_preserved (void)
 Priority ordering must be preserved after a blocked-job skip. More...
 
void test_agent_transition_null_owner_safe (void)
 agent_transition() must not crash when agent->owner is NULL.
 
void test_meta_agent_negative_max_run_is_unlimited (void)
 Regression: max_run < 0 must mean unlimited, not "limit reached". More...
 

Variables

CU_TestInfo tests_job []
 

Detailed Description

Unit test for job operations.

Definition in file testJob.c.

Function Documentation

◆ Prepare_Testing_Data_Job()

int Prepare_Testing_Data_Job ( scheduler_t scheduler)

Local function for testing data prepare

Definition at line 27 of file testJob.c.

◆ test_job_event()

void test_job_event ( )

Test for job events.

Test:
  1. Initialize scheduler and database
  2. Create new database_update_event() to load data
  3. Get the job from scheduler and call
    1. job_verbose_event() and check if job is updated
    2. job_pause_event() and check if job is paused
    3. job_restart_event() and check if job is restarted
    4. job_priority_event() and check if job is restarted
    5. job_fail_event() and check if job is failed

Definition at line 47 of file testJob.c.

◆ test_job_fun()

void test_job_fun ( )

Test for job functions.

Test:
  1. Initialize scheduler and database
  2. Create new database_update_event() to load data
  3. Get the job from scheduler and call
    1. job_next() and check the job queue id
    2. next_job() and check the job is NOT NULL and its id is 1
    3. peek_job() and check the job is NOT NULL and its id is 1
    4. active_jobs() and check the result is 0

Definition at line 106 of file testJob.c.

◆ test_meta_agent_negative_max_run_is_unlimited()

void test_meta_agent_negative_max_run_is_unlimited ( void  )

Regression: max_run < 0 must mean unlimited, not "limit reached".

The old isMaxLimitReached() used (max_run <= run_count), so max_run=-1 with run_count=0 wrongly reported the limit reached and blocked unlimited agents. The guard max_run >= 0 fixes it: max_run=-1 is unlimited, max_run=0 blocks.

Definition at line 292 of file testJob.c.

◆ test_scheduler_high_load_no_false_stale()

void test_scheduler_high_load_no_false_stale ( void  )

Jobs blocked at max_run must not be reaped as stale.

Ages 300 jobs past the grace period then runs one scheduler_update() cycle. The skip loop refreshes checkedout_at so the stale reaper finds nothing.

Definition at line 155 of file testJob.c.

◆ test_scheduler_priority_order_preserved()

void test_scheduler_priority_order_preserved ( void  )

Priority ordering must be preserved after a blocked-job skip.

Three jobs (-10/0/+10 priority), all blocked. After scheduler_update() the highest-priority job must still be at the front of the queue.

Definition at line 211 of file testJob.c.

Variable Documentation

◆ tests_job

CU_TestInfo tests_job[]
Initial value:
=
{
{"Test job_event", test_job_event },
{"Test job_fun", test_job_fun },
{"Test 15-users-20-uploads no false stale kill",test_scheduler_high_load_no_false_stale},
{"Test priority order preserved after skip", test_scheduler_priority_order_preserved},
{"Test agent_transition null owner safe", test_agent_transition_null_owner_safe },
{"Test max_run=-1 means unlimited", test_meta_agent_negative_max_run_is_unlimited},
CU_TEST_INFO_NULL
}
void test_scheduler_priority_order_preserved(void)
Priority ordering must be preserved after a blocked-job skip.
Definition: testJob.c:211
void test_job_fun()
Test for job functions.
Definition: testJob.c:106
void test_job_event()
Test for job events.
Definition: testJob.c:47
void test_agent_transition_null_owner_safe(void)
agent_transition() must not crash when agent->owner is NULL.
Definition: testJob.c:272
void test_meta_agent_negative_max_run_is_unlimited(void)
Regression: max_run < 0 must mean unlimited, not "limit reached".
Definition: testJob.c:292
void test_scheduler_high_load_no_false_stale(void)
Jobs blocked at max_run must not be reaped as stale.
Definition: testJob.c:155

Definition at line 321 of file testJob.c.