24 #include <libfossscheduler.h> 32 #include <libfocunit.h> 35 #define COMMIT_HASH "COMMIT_HASH Unknown" 61 #define FROM_UNIT "UNIT\n" 62 #define VERBOSE_TEST 7 63 #define NC_TEST "Not a Command\n" 65 #define write_con(...) \ 66 fprintf(write_to, __VA_ARGS__); \ 79 FO_ASSERT_TRUE_FATAL(!pipe(in_sub));
80 FO_ASSERT_TRUE_FATAL(!pipe(out_sub));
82 stdin_t = dup(fileno(stdin));
83 stdout_t = dup(fileno(stdout));
85 dup2(out_sub[1], fileno(stdout));
86 dup2(in_sub[0], fileno(stdin));
87 read_from = fdopen(out_sub[0],
"rb");
88 write_to = fdopen(in_sub[1],
"wb");
110 dup2(stdin_t, fileno(stdin));
111 dup2(stdout_t, fileno(stdout));
126 FO_ASSERT_FALSE(
valid);
127 FO_ASSERT_STRING_EQUAL(fgets(
buffer,
sizeof(
buffer), read_from),
"OK\n");
129 write_con(
"CLOSE\n");
143 FO_ASSERT_FALSE(
valid);
148 write_con(
"CLOSE\n");
159 FO_ASSERT_FALSE(
valid);
160 FO_ASSERT_PTR_NOT_NULL(fgets(
buffer,
sizeof(
buffer), read_from));
162 FO_ASSERT_STRING_EQUAL(
buffer, COMMIT_HASH);
164 write_con(
"CLOSE\n");
182 char* argv[] = {
"./testlibs",
"--config=./scheddata"};
188 FO_ASSERT_FALSE(
valid);
192 fprintf(stdout, FROM_UNIT);
193 FO_ASSERT_PTR_NOT_NULL(fgets(
buffer,
sizeof(
buffer), read_from));
194 FO_ASSERT_STRING_EQUAL(
buffer, FROM_UNIT);
197 while (strcmp(
buffer, FROM_UNIT) != 0)
198 FO_ASSERT_PTR_NOT_NULL(fgets(
buffer,
sizeof(
buffer), read_from));
214 char* argv[] = {
"./testlibs",
"--config=./scheddata",
"--scheduler_start"};
221 FO_ASSERT_FALSE(
valid);
227 FO_ASSERT_PTR_NOT_NULL(tmp);
228 FO_ASSERT_STRING_EQUAL(
buffer, COMMIT_HASH);
231 FO_ASSERT_PTR_NOT_NULL(tmp);
232 FO_ASSERT_STRING_EQUAL(tmp,
"OK\n");
237 FO_ASSERT_STRING_EQUAL(
252 write_con(
"CLOSE\n");
255 FO_ASSERT_FALSE(
valid);
275 FO_ASSERT_FALSE(
valid);
290 write_con(
"VERBOSE %d\n", VERBOSE_TEST);
296 FO_ASSERT_FALSE(
valid);
311 write_con(
"VERSION\n");
317 FO_ASSERT_FALSE(
valid);
336 FO_ASSERT_STRING_EQUAL(ret, NC_TEST);
337 FO_ASSERT_TRUE(
valid);
351 write_con(
"CLOSE\n");
369 FO_ASSERT_STRING_EQUAL(fgets(
buffer,
sizeof(
buffer), read_from),
"BYE 2\n");
370 FO_ASSERT_FALSE(
valid);
397 FO_ASSERT_STRING_EQUAL(
406 CU_TestInfo fossscheduler_testcases[] =
408 {
"fossscheduler set up",
set_up},
void test_scheduler_next_end()
Tests sending "END\\n" to the stdin for the scheduler next function.
int valid
If the information stored in buffer is valid.
void signal_connect_version()
Test for version string.
int items_processed
The number of items processed by the agent.
void test_scheduler_no_connect()
Test for fo_scheduler_connect() with no new connection.
void test_scheduler_next_close()
Tests sending "CLOSE\\n" to stdin for the scheduler next function.
void tear_down(void)
This function closes the pipes created in the setup function and returns stdin and stdout to their or...
char * fo_scheduler_current()
Get the last read string from the scheduler.
void test_scheduler_next_verbose()
Tests sending "VERBOSE #\\n" to the stdin for the scheduler next function.
void fo_scheduler_disconnect(int retcode)
Disconnect the scheduler connection.
void fo_scheduler_connect(int *argc, char **argv, PGconn **db_conn)
Establish a connection between an agent and the scheduler.
void test_scheduler_next_oth()
Tests scheduler for non commands.
void signal_connect_end()
Test for fo_scheduler_next() blocking.
char buffer[]
The last thing received from the scheduler.
void test_scheduler_next_version()
Tests sending "VERSION\\n" to the stdin for the scheduler next function.
void test_scheduler_connect()
Test for fo_scheduler_connect() with a new connection.
void fo_heartbeat()
Internal function to send a heartbeat to the scheduler along with the number of items processed...
void test_scheduler_current()
Tests the scheduler current function.
void set_up(void)
Since the fossscheduler library depends on reading and writing very specific data to stdin and stdout...
int sscheduler
Whether the agent was started by the scheduler.
char * fo_scheduler_next()
Get the next data to process from the scheduler.
void fo_scheduler_heart(int i)
This function must be called by agents to let the scheduler know they are alive and how many items th...
int agent_verbose
Common verbose flags for the agents, this is used so that the scheduler can change the verbose level ...
void test_scheduler_disconnect()
Tests the scheduler disconnection function.
void test_scheduler_heart()
Test the scheduler heart function. This function must set up the heartbeat again so that it can check...
void signal_connect_verbose()
Serves the same purpose for the verbose command as the signal_connect_end() function does for the end...