PreviousUpNext

15.4.1091  src/lib/std/src/hostthread/io-bound-task-hostthreads-unit-test.pkg

## io-bound-task-hostthreads-unit-test.pkg
#
# Unit/regression test functionality for
#
#    src/lib/std/src/hostthread/io-bound-task-hostthreads.pkg
#
# (The io_bound_task_hostthreads server offloads cpu-intensive
# tasks from the main thread-scheduler hostthread.)

# Compiled by:
#     src/lib/test/unit-tests.lib

# Run by:
#     src/lib/test/all-unit-tests.pkg


stipulate
#   package hth =  hostthread;                                                  # hostthread                    is from   src/lib/std/src/hostthread.pkg
    package io  =  io_bound_task_hostthreads;                                   # io_bound_task_hostthreads     is from   src/lib/std/src/hostthread/io-bound-task-hostthreads.pkg
    #
    sleep = makelib::scripting_globals::sleep;
herein

    package io_bound_task_hostthreads_unit_test {
        #
        include package   unit_test;                                            # unit_test                     is from   src/lib/src/unit-test.pkg
 
        name =  "src/lib/std/src/hostthread/io-bound-task-hostthreads-unit-test.pkg";
 
 
        fun verify_basic__servercount__operation ()
            =
            {   # Pretty minimal test:  :-)
                #
                assert(  io::get_count_of_live_hostthreads () >= 0  );
            };

        fun verify_basic__start__operation ()
            =
            {   before_servercount =   io::get_count_of_live_hostthreads ();
                #
                io::change_number_of_server_hostthreads_to "cpu-bound-task-hostthreads-unit-test" (before_servercount + 2);

#               count2 =  io::start  "lagserver-hostthread-unit-test";
#               count3 =  io::start  "lagserver-hostthread-unit-test";
                #
                sleep 0.01;
                #
                after_servercount =   io::get_count_of_live_hostthreads ();
                #
                assert (after_servercount == before_servercount + 2);
            };

        fun verify_basic__echo__operation ()
            =
            {   echoed_text = REF "";
                #
                io::echo  { what => "foo",  reply => (\\ what = (echoed_text := what)) };
                #
                sleep 0.01;
                #
                assert( *echoed_text == "foo" );
            };

        fun verify_basic__do__operation ()
            =
            {   result1 = REF 0;
                result2 = REF 0;
                #
                io::do  (\\ () =  result1 := 1);
                io::do  (\\ () =  result2 := 2);
                #
                sleep 0.01;
                #
                assert( *result1 == 1 );
                assert( *result2 == 2 );
            };

        fun verify_basic__stop__operation ()
            =
            {   before_servercount =   io::get_count_of_live_hostthreads ();

                io::change_number_of_server_hostthreads_to "cpu-bound-task-hostthreads-unit-test" (before_servercount - 2);

#               io::stop  { per_who => "lagserver-hostthread-unit-test",  reply => (\\ _ = ()) };
#               io::stop  { per_who => "lagserver-hostthread-unit-test",  reply => (\\ _ = ()) };
                #
                sleep 0.01;
                #
                after_servercount =   io::get_count_of_live_hostthreads ();

                assert (after_servercount == before_servercount - 2);
            };

        fun run ()
            =
            {   printf "\nDoing %s:\n" name;   
                #
                verify_basic__servercount__operation ();
                verify_basic__start__operation ();
                verify_basic__echo__operation ();
                verify_basic__do__operation ();
                verify_basic__stop__operation ();
                #
                summarize_unit_tests  name;
            };
    };
end;


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext