create test db
[m6w6/ext-pq] / tests / notify001.phpt
1 --TEST--
2 notify
3 --SKIPIF--
4 <?php include "_skipif.inc"; ?>
5 --FILE--
6 <?php
7 echo "Test\n";
8
9 include "_setup.inc";
10
11 $consumer = new pq\Connection(PQ_DSN);
12 $consumer->listen("test", function($channel, $message, $pid) {
13 printf("%s(%d): %s\n", $channel, $pid, $message);
14 });
15
16 $producer = new pq\Connection(PQ_DSN);
17 $producer->notify("test", "this is a test");
18
19 $consumer->exec("select 1");
20
21 $producer->notify("test", "this is an async test");
22
23 $r = array($consumer->socket);
24 $w = null; $e = null;
25 stream_select($r, $w, $e, NULL);
26 $consumer->poll();
27
28 $producer->notify("other", "this should not show up");
29
30 stream_select($r, $w, $e, 0,1000);
31 $consumer->poll();
32
33 $producer->notify("test", "just to be sure");
34
35 $r = array($consumer->socket);
36 $w = null; $e = null;
37 stream_select($r, $w, $e, 0,1000);
38 $consumer->poll();
39
40 $consumer->unlisten("test");
41
42 $producer->notify("test", "this shouldn't show up either");
43
44 $r = array($consumer->socket);
45 $w = null; $e = null;
46 stream_select($r, $w, $e, 0,1000);
47 $consumer->poll();
48
49 ?>
50 DONE
51 --EXPECTF--
52 Test
53 test(%d): this is a test
54 test(%d): this is an async test
55 test(%d): just to be sure
56 DONE