Revision 1845
| trunk/nntpgrab_core/download_queue.c (revision 1845) | ||
|---|---|---|
| 503 | 503 |
/* Do we need to skip this file? */ |
| 504 | 504 |
if ((*file)->status == TASK_STATE_SKIPPED) {
|
| 505 | 505 |
/* Ignore */ |
| 506 |
server_positions[server_id].part_list = NULL; |
|
| 506 | 507 |
list2 = g_list_next(list2); |
| 507 | 508 |
continue; |
| 508 | 509 |
} |
| ... | ... | |
| 511 | 512 |
if ((*file)->file_is_downloaded) {
|
| 512 | 513 |
// Yes, remove it from the files_to_download list and start over |
| 513 | 514 |
(*collection)->files_to_download = g_list_remove((*collection)->files_to_download, list2->data); |
| 515 |
server_positions[server_id].part_list = NULL; |
|
| 514 | 516 |
list2 = (*collection)->files_to_download; |
| 515 | 517 |
continue; |
| 516 | 518 |
} |
| 517 | 519 |
|
| 518 | 520 |
if ((*file)->now_decoding) {
|
| 521 |
server_positions[server_id].part_list = NULL; |
|
| 519 | 522 |
list2 = g_list_next(list2); |
| 520 | 523 |
continue; |
| 521 | 524 |
} |
| 522 | 525 |
|
| 523 | 526 |
// Is this file being removed? |
| 524 | 527 |
if ((*file)->stop_flag) {
|
| 528 |
server_positions[server_id].part_list = NULL; |
|
| 525 | 529 |
list2 = g_list_next(list2); |
| 526 | 530 |
continue; |
| 527 | 531 |
} |
| ... | ... | |
| 607 | 611 |
continue; |
| 608 | 612 |
} |
| 609 | 613 |
|
| 610 |
if (file_tmp->now_decoding) {
|
|
| 614 |
if (file_tmp->now_decoding || !file_tmp->file_is_downloaded) {
|
|
| 611 | 615 |
*nothing_to_download_or_active = FALSE; |
| 612 | 616 |
} |
| 613 | 617 |
|
| ... | ... | |
| 617 | 621 |
list = g_list_next(list); |
| 618 | 622 |
} |
| 619 | 623 |
|
| 620 |
if (*nothing_to_download_or_active == TRUE && server_positions[server_id].task_probably_ready == FALSE) {
|
|
| 621 |
/* There was no task ready for this server, so we skipped the tests for looking up new tasks |
|
| 622 |
* and only checked if there any tasks being decoded at the moment. As there probably still |
|
| 623 |
* are downloads going on, we need to reset the nothing_to_download_or_active flag to FALSE |
|
| 624 |
* to avoid that the schedular gets paused */ |
|
| 625 |
*nothing_to_download_or_active = FALSE; |
|
| 626 |
} |
|
| 627 |
|
|
| 628 | 624 |
*collection = NULL; |
| 629 | 625 |
*file = NULL; |
| 630 | 626 |
*part = NULL; |
| trunk/Makefile.decl (revision 1845) | ||
|---|---|---|
| 33 | 33 |
elif test -n "${TEST_PROGS}" ; then \
|
| 34 | 34 |
${GTESTER} --verbose $$test_options -o `mktemp "$$GTESTER_LOGDIR/log-XXXXXX"` ${TEST_PROGS} ; \
|
| 35 | 35 |
fi ; \ |
| 36 |
exit 0; \ |
|
| 36 | 37 |
} |
| 37 | 38 |
@ ignore_logdir=true ; \ |
| 38 | 39 |
if test -z "$$GTESTER_LOGDIR" ; then \ |
| trunk/tests/test_download_queue.c (revision 1845) | ||
|---|---|---|
| 434 | 434 |
} |
| 435 | 435 |
|
| 436 | 436 |
static void |
| 437 |
test_download_queue_get_next_part_to_download_one_server_all_available(void *data, gconstpointer user_data) |
|
| 437 |
test_download_queue_get_next_part_to_download_one_server_generic(gboolean all_available) |
|
| 438 | 438 |
{
|
| 439 |
/* There should be 10 files with 4 parts each in the download queue now |
|
| 440 |
* Assume for this testcase that all parts are available on the server */ |
|
| 439 |
/* There should be 10 files with 4 parts each in the download queue now */ |
|
| 441 | 440 |
int i, j; |
| 442 | 441 |
|
| 443 | 442 |
NNTPCollection *prev_collection = NULL; |
| ... | ... | |
| 450 | 449 |
|
| 451 | 450 |
GList *list, *files = NULL; |
| 452 | 451 |
|
| 453 |
for (i = 0; i < 10; i++) {
|
|
| 452 |
for (i = 1; i <= 10; i++) {
|
|
| 454 | 453 |
prev_file = NULL; |
| 455 | 454 |
|
| 456 |
for (j = 0; j < 4; j++) {
|
|
| 455 |
for (j = 1; j <= 4; j++) {
|
|
| 457 | 456 |
/* There 1 server configured at the moment, so a request for the next part for server_id 0 |
| 458 | 457 |
* should return TRUE and nothing_do_download should_or_active be FALSE */ |
| 459 | 458 |
if (!download_queue_get_next_part_to_download(&collection, &file, &part, 0, ¬hing_to_download_or_active)) {
|
| ... | ... | |
| 461 | 460 |
FAIL_TEST("download_queue_get_next_part_to_download returned FALSE while it isn't expected");
|
| 462 | 461 |
return; |
| 463 | 462 |
} else {
|
| 463 |
char *expected_subject = g_strdup_printf("file %i", i);
|
|
| 464 |
|
|
| 464 | 465 |
g_assert_cmpint(nothing_to_download_or_active, ==, FALSE); |
| 465 | 466 |
g_assert(collection != NULL); |
| 466 | 467 |
g_assert(file != NULL); |
| 467 | 468 |
g_assert(part != NULL); |
| 468 | 469 |
|
| 470 |
g_assert_cmpint(part->part_num, ==, j); |
|
| 471 |
g_assert_cmpstr(file->subject, ==, expected_subject); |
|
| 472 |
|
|
| 473 |
g_free(expected_subject); |
|
| 474 |
|
|
| 469 | 475 |
if (prev_collection == NULL) {
|
| 470 | 476 |
prev_collection = collection; |
| 471 | 477 |
} else {
|
| ... | ... | |
| 480 | 486 |
} |
| 481 | 487 |
} |
| 482 | 488 |
|
| 483 |
/* Update the status of the part so that everything got completed succesfully */ |
|
| 484 |
download_queue_update_part_status("server1", 0, collection, file, part, 0, TRUE, FALSE, FALSE);
|
|
| 489 |
/* Update the status of the part */ |
|
| 490 |
if (!all_available && j % 2 == 0) {
|
|
| 491 |
/* Indicate the every second part isn't available on the server and it shouldn't be retried again */ |
|
| 492 |
download_queue_update_part_status("server1", 0, collection, file, part, 0, FALSE, FALSE, TRUE);
|
|
| 493 |
} else {
|
|
| 494 |
/* Indicate that the file was downloaded succesfully */ |
|
| 495 |
download_queue_update_part_status("server1", 0, collection, file, part, 0, TRUE, FALSE, FALSE);
|
|
| 496 |
} |
|
| 485 | 497 |
|
| 486 | 498 |
collection = NULL; |
| 487 | 499 |
file = NULL; |
| ... | ... | |
| 507 | 519 |
while (list) {
|
| 508 | 520 |
file = (NNTPFile*) list->data; |
| 509 | 521 |
|
| 510 |
file->file_is_downloaded = TRUE; |
|
| 511 |
file->now_decoding = FALSE; |
|
| 512 |
file->status = TASK_STATE_FINISHED_COMPLETE; |
|
| 522 |
if (!all_available && g_list_index(files, file) % 2 == 0) {
|
|
| 523 |
/* Indicate that not all parts were available */ |
|
| 524 |
download_queue_mark_file_as_decoded_and_unref(prev_collection, file, "somefilename", TASK_STATE_FINISHED_INCOMPLETE); |
|
| 525 |
} else {
|
|
| 526 |
/* Indicate that all parts were decoded succesfully */ |
|
| 527 |
download_queue_mark_file_as_decoded_and_unref(prev_collection, file, "somefilename", TASK_STATE_FINISHED_COMPLETE); |
|
| 528 |
} |
|
| 513 | 529 |
|
| 514 | 530 |
list = g_list_next(list); |
| 515 | 531 |
} |
| ... | ... | |
| 528 | 544 |
} |
| 529 | 545 |
} |
| 530 | 546 |
|
| 547 |
static void |
|
| 548 |
test_download_queue_get_next_part_to_download_one_server_all_available(void *data, gconstpointer user_data) |
|
| 549 |
{
|
|
| 550 |
/* Assume for this testcase that all parts are available on the server */ |
|
| 551 |
test_download_queue_get_next_part_to_download_one_server_generic(TRUE); |
|
| 552 |
} |
|
| 553 |
|
|
| 554 |
static void |
|
| 555 |
test_download_queue_get_next_part_to_download_one_server_some_available(void *data, gconstpointer user_data) |
|
| 556 |
{
|
|
| 557 |
/* Assume for this testcase that some parts are available on the server */ |
|
| 558 |
test_download_queue_get_next_part_to_download_one_server_generic(FALSE); |
|
| 559 |
} |
|
| 560 |
|
|
| 531 | 561 |
int |
| 532 | 562 |
main(int argc, char **argv) |
| 533 | 563 |
{
|
| ... | ... | |
| 565 | 595 |
test_download_queue_get_next_part_to_download_setup_one_server_after, |
| 566 | 596 |
test_download_queue_get_next_part_to_download_one_server_all_available, |
| 567 | 597 |
test_download_queue_get_next_part_to_download_teardown_one_server); |
| 598 |
g_test_add("/download_queue/get_next_part_to_download/one_server/before/some_available", void, NULL,
|
|
| 599 |
test_download_queue_get_next_part_to_download_setup_one_server_before, |
|
| 600 |
test_download_queue_get_next_part_to_download_one_server_some_available, |
|
| 601 |
test_download_queue_get_next_part_to_download_teardown_one_server); |
|
| 602 |
g_test_add("/download_queue/get_next_part_to_download/one_server/after/some_available", void, NULL,
|
|
| 603 |
test_download_queue_get_next_part_to_download_setup_one_server_after, |
|
| 604 |
test_download_queue_get_next_part_to_download_one_server_all_available, |
|
| 605 |
test_download_queue_get_next_part_to_download_teardown_one_server); |
|
| 568 | 606 |
|
| 569 | 607 |
/* Perform the tests */ |
| 570 | 608 |
ret = g_test_run(); |
Also available in: Unified diff
NNTPGrab

