Sharing varible between two add_actions

First of all, the order in which you use add_action is not relevant. The only thing it does is keep a tab of actions to undertake once the hook is encountered. Only when there are several functions on the same hook, the priority of the added action becomes relevant (read more).

So, if your global variable isn’t changed, this means that the hook changing it (wpcf7_before_send_mail) is called AFTER the hook where you test if it’s been changed (wp_ajax_test_get_form_post). Or maybe the changing hook is not called at all. You can change the latter by echoing something inside test_before_send_mail(). If nothing is printed, the hook is not called, if there is, the hook is called too late.

Depending on what you’re looking to achieve the easiest solution would be to attach test_get_form_post_callback to wpcf7_before_send_mail as well, and use priorities to assure the right execution order.

If you are in command of both test_before_send_mail() and test_get_form_post_callback the cleanest solution would be to include a filter hook in one of the functions, eliminating the need for a global variable. Like this:

function wpse374144_main ($args) {
  ... do stuff
  $var = something;
  $var = apply_filters ('wpse374144_main_filter', $var);
  }

 add_filter ('wpse374144_main_filter','wpse374144_main_callback',10,1);

 function wpse374144_main_callback ($var) {
   ... do stuff
   return $var;
   }