aboutsummaryrefslogtreecommitdiffstats
path: root/lib/hipe/test/basic_SUITE_data/basic_receive.erl
blob: 5f865d7b7ac24acd057ce14de7d94b5c56e4b2c7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
%%% -*- erlang-indent-level: 2 -*-
%%%-------------------------------------------------------------------
%%% Author: Kostis Sagonas
%%%
%%% Contains code examples that test correct handling of receives.
%%%-------------------------------------------------------------------
-module(basic_receive).

-export([test/0]).

test() ->
  ok = test_wait_timeout(),
  ok = test_double_timeout(),
  ok = test_reschedule(),
  ok.

%%--------------------------------------------------------------------

test_wait_timeout() ->
  receive after 42 -> ok end.

%%--------------------------------------------------------------------

test_double_timeout() ->
  self() ! foo,
  self() ! another_foo,
  receive
    non_existent -> weird
  after 0 -> timeout
  end,
  receive
    foo -> ok
  after 1000 -> timeout
  end.

%%--------------------------------------------------------------------
%% Check that RESCHEDULE returns from BIFs work.

test_reschedule() ->
  erts_debug:set_internal_state(available_internal_state, true),
  First = self(),
  Second = spawn(fun() -> doit(First) end),
  receive
    Second -> ok
  end,
  receive
  after 42 -> ok
  end,
  erts_debug:set_internal_state(hipe_test_reschedule_resume, Second),
  ok.

doit(First) ->
  First ! self(),
  erts_debug:set_internal_state(hipe_test_reschedule_suspend, 1).

%%--------------------------------------------------------------------