anchor.diff:      Subscribe = packet:gen_subscribe(16, "retain/qos0/test", 0),
       Suback = packet:gen_suback(16, 0),
       {ok, Socket} = packet:do_client_connect(Connect, Connack, []),
  -    enable_on_publish(),
  -    enable_on_subscribe(),
  -    %% Send retained message
  -    ok = gen_tcp:send(Socket, Publish),
  -    ok = gen_tcp:send(Socket, Subscribe),
  -    ok = packet:expect_packet(Socket, "suback", Suback),
  -    ok = packet:expect_packet(Socket, "publish", Publish),
  -    disable_on_publish(),
  -    disable_on_subscribe(),
  +    %% Send retained message
  +    ok = gen_tcp:send(Socket, Publish),
  +    ok = gen_tcp:send(Socket, Subscribe),
  +    ok = packet:expect_packet(Socket, "suback", Suback),
  +    ok = packet:expect_packet(Socket, "publish", Publish),
       ok = gen_tcp:close(Socket).
   
   retain_qos0_repeated_test(_) ->
       Connect = packet:gen_connect("retain-qos0-rep-test", [{keepalive,60}]),
       Connack = packet:gen_connack(0),
  -    Publish = packet:gen_publish("retain/qos0/test", 0, <<"retained message">>, [{retain, true}]),
  -    Subscribe = packet:gen_subscribe(16, "retain/qos0/test", 0),
  -    Suback = packet:gen_suback(16, 0),
  -    Unsubscribe = packet:gen_unsubscribe(13, "retain/qos0/test"),
  +    Publish = packet:gen_publish("retain/qos0/reptest", 0, <<"retained message">>, [{retain, true}]),
  +    Subscribe = packet:gen_subscribe(16, "retain/qos0/reptest", 0),
  +    Suback = packet:gen_suback(16, 0),
  +    Unsubscribe = packet:gen_unsubscribe(13, "retain/qos0/reptest"),
       Unsuback = packet:gen_unsuback(13),
       {ok, Socket} = packet:do_client_connect(Connect, Connack, []),
  -    enable_on_publish(),
  -    enable_on_subscribe(),
       %% Send retained message
       ok = gen_tcp:send(Socket, Publish),
       ok = gen_tcp:send(Socket, Subscribe),
  
positive.code:     %% Receive the empty payload msg as normal publish.
      ok = packet:expect_packet(Socket, "publish", RetainClearSub),
      {error, timeout} = gen_tcp:recv(Socket, 256, 1000),
      disable_on_publish(),
      disable_on_subscribe(),
      ok = gen_tcp:close(Socket).
  
  retain_wildcard_test(_) ->
      Connect = packet:gen_connect("retain-wildcard-test", [{keepalive,60}]),
      Connack = packet:gen_connack(0),
      Publish = packet:gen_publish("retain/wildcard/test", 0, <<"retained message">>, [{retain, true}]),
      Subscribe = packet:gen_subscribe(16, "retain/+/#", 0),
      Suback = packet:gen_suback(16, 0),
      {ok, Socket} = packet:do_client_connect(Connect, Connack, []),
      enable_on_publish(),
      enable_on_subscribe(),
      %% Send retained message
      ok = gen_tcp:send(Socket, Publish),
      ok = gen_tcp:send(Socket, Subscribe),
      ok = packet:expect_packet(Socket, "suback", Suback),
      ok = packet:expect_packet(Socket, "publish", Publish),
      disable_on_publish(),
      disable_on_subscribe(),
      ok = gen_tcp:close(Socket).
  
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %%% Hooks (as explicit as possible)
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  hook_auth_on_subscribe(_,{"", <<"retain-qos0-test">>}, [{[<<"retain">>, <<"qos0">>, <<"test">>],0}]) -> ok;
  hook_auth_on_subscribe(_,{"", <<"retain-qos0-rep-test">>}, [{[<<"retain">>, <<"qos0">>, <<"test">>],0}]) -> ok;
  hook_auth_on_subscribe(_,{"", <<"retain-qos0-fresh-test">>}, [{[<<"retain">>,<<"qos0">>,<<"test">>],0}]) -> ok;
  hook_auth_on_subscribe(_,{"", <<"retain-clear-test">>}, [{[<<"retain">>,<<"clear">>,<<"test">>],0}]) -> ok;
  hook_auth_on_subscribe(_,{"", <<"retain-qos1-test">>}, [{[<<"retain">>,<<"qos1">>,<<"test">>],0}]) -> ok;
  hook_auth_on_subscribe(_,{"", <<"retain-wildcard-test">>}, [{[<<"retain">>, <<"+">>, <<"#">>],0}]) -> ok.
  
  hook_auth_on_publish(_, _, _MsgId, [<<"retain">>,<<"qos0">>,<<"test">>], <<"retained message">>, true) -> ok;
  %% retain_qos0_clear(_) Both cases must be covered retain and clear-retain
  hook_auth_on_publish(_, _, _MsgId, [<<"retain">>,<<"clear">>,<<"test">>], <<"retained message">>, true) -> ok;
  hook_auth_on_publish(_, _, _MsgId, [<<"retain">>,<<"clear">>,<<"test">>], <<>>, true) -> ok;
  %
  hook_auth_on_publish(_, _, _MsgId, [<<"retain">>,<<"qos1">>,<<"test">>], <<"retained message">>, true) -> ok;
  hook_auth_on_publish(_, _, _MsgId, [<<"retain">>,<<"wildcard">>,<<"test">>], <<"retained message">>, true) -> ok.
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %%% Helper
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  
negative.code:     Unsubscribe = packet:gen_unsubscribe(593, "retain/clear/test"),
      Unsuback = packet:gen_unsuback(593),
      {ok, Socket} = packet:do_client_connect(Connect, Connack, []),
      %% Send retained message
      ok = gen_tcp:send(Socket, Publish),
      %% Subscribe to topic, we should get the retained message back.
  