factor out remote_object method
[scpubgit/TenDotTcl.git] / t / connection.t
CommitLineData
0e93bc12 1BEGIN { exec(tclsh => 't/tcl/harness.tcl' => $0) }
2
3package require ten
4package require json::write
5
e63453e3 6if {[array names ::env PERL5LIB]==""} {
7 array set ::env [list PERL5LIB t/lib]
8} else {
9 array set ::env [list PERL5LIB "t/lib:$::env(PERL5LIB)"]
10}
11
0e93bc12 12set connector [ten::connector::perl %AUTO%]
13
14set conn [$connector connect]
15
61761da2 16proc jws {args} {
17 set ret {}
18 foreach str $args {
19 lappend ret [ json::write string $str ]
20 }
21 return $ret
22}
23
0e93bc12 24set f1 [
61761da2 25 $conn send call {*}[jws class_call_handler 0 call Sys::Hostname hostname]
0e93bc12 26]
27
28set ready_args ""
29
30$f1 on_ready [list apply {{name future} {set $name [$future get]}} "[namespace current]::ready_args" ]
31
9540dca1 32set my_host [exec hostname]
33
47f04c56 34is [$f1 await_get] $my_host "hostname returned ok via get"
9540dca1 35
36is $ready_args $my_host "hostname returned ok via on_ready"
61761da2 37
e63453e3 38set ortestdata [[$conn send call {*}[jws class_call_handler 0 call ORTestClass new]] await_get]
39
40set ortestoid [lindex $ortestdata 0 1]
41
451af734 42set ortest [$conn remote_object $ortestoid]
e63453e3 43
451af734 44cmp_ok != [pid] [$ortest call pid] "pid is different on the other side"
e63453e3 45
451af734 46is [$ortest call counter] 0 "Counter at 0"
e63453e3 47
451af734 48is [$ortest call increment] 1 "Incrememt to 1"
e63453e3 49
451af734 50is [$ortest call counter] 1 "Counter at 1"
51
52$ortest destroy
e63453e3 53
61761da2 54done_testing