What is wrong with your code is that the code that outputs the content of the block needs to be executed, such as:

    $block['content'] = test_get_block_content();

This code makes sense if the code needs to output something in the page; if the code that needs to be executed doesn't need to output anything in the page, then [hook_exit()][1] is always executed, even on cached pages. The documentation for that hook reports the following text:

> Only use this hook if your code must run even for cached page views. If you have code which must run once on all non cached pages, use `hook_init()` instead. 




  [1]: http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hook_exit/6