Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

test concurrent connection setup

  • Loading branch information...
commit 9c6095832cb4da0b10cd86fd120d18e660470b8a 1 parent fd5d53e
@moonpolysoft moonpolysoft authored
View
19 src/test/resources/receive_two.escript
@@ -0,0 +1,19 @@
+#!/usr/bin/env escript
+%%! -smp enable -sname test@localhost -setcookie test
+
+main([]) ->
+ register(receiver,self()),
+ io:format("ready~n"),
+ receive
+ {One,Pid} ->
+ io:format("~p~n", [One]),
+ Pid ! ok
+ end,
+ receive
+ {Two,Pid} ->
+ io:format("~p~n", [Two]),
+ Pid ! ok
+ end,
+ receive
+ ok -> ok
+ end.
View
22 src/test/scala/scalang/NodeSpec.scala
@@ -47,6 +47,28 @@ class NodeSpec extends SpecificationWithJUnit {
node.channels.keySet.toSet must contain(Symbol("test@localhost"))
}
+ "not open two channels in a race" in {
+ println("twooooooo")
+ node = Node(Symbol("scala@localhost"), cookie)
+ erl = Escript("receive_two.escript")
+ ReadLine(erl) //ready
+ Thread.sleep(100)
+ val mbox = node.spawnMbox
+ val pid = mbox.self
+ val threads = Seq(1,2).map { n =>
+ new Thread {
+ override def run {
+ //if (n == 1) Thread.sleep(100)
+ node.getOrConnectAndSend(Symbol("test@localhost"), RegSend(pid,'receiver,(n,pid)))
+ }
+ }
+ }
+ threads.foreach( t => t.start )
+ threads.foreach( t => t.join )
+ mbox.receive
+ mbox.receive
+ }
+
"accept pings" in {
node = Node(Symbol("scala@localhost"), cookie)
erl = ErlangVM("tmp@localhost", cookie, Some("io:format(\"~p~n\", [net_adm:ping('scala@localhost')])."))
View
11 src/test/scala/scalang/TestHelper.scala
@@ -44,3 +44,14 @@ object ReadLine {
line
}
}
+
+object ReadError {
+ def apply(proc : SysProcess) : String = {
+ val read = new BufferedReader(new InputStreamReader(proc.getErrorStream))
+ val line = read.readLine
+ if(line == null) {
+ throw new RuntimeException("error getting result from escript. ensure that erlang is installed and available on the path.")
+ }
+ line
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.