From 3ac7beb4bf551f92aca0358f9bb5fa46876f19c7 Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Tue, 14 Feb 2023 02:28:27 -0500 Subject: More cleanup/refactoring of peering. Start trying to test IPC statements. --- laptop.tcl | 31 ++++++++++++++----------------- lib/peer.tcl | 10 +++++----- lib/process.tcl | 10 ++++++---- test/process.tcl | 16 ++++++++++++---- 4 files changed, 37 insertions(+), 30 deletions(-) diff --git a/laptop.tcl b/laptop.tcl index 61df355a..b45a1524 100644 --- a/laptop.tcl +++ b/laptop.tcl @@ -205,24 +205,21 @@ if {[info exists ::shareNode]} { } err]} { puts "error syncing: $err" puts "Proceeding without sharing to table." - unset ::shareNode - } - lappend auto_path "./vendor" - package require websocket - - source "lib/peer.tcl" - peer $::shareNode - - Assert "laptop.tcl" is providing root statements - Assert "laptop.tcl" wishes $::nodename shares statements like \ - [list "laptop.tcl" is providing root statements] - Assert "laptop.tcl" wishes $::nodename shares statements like \ - [list "laptop.tcl" claims /program/ has program code /code/] - Assert "laptop.tcl" wishes $::nodename shares statements like \ - [list "laptop.tcl" claims /program/ has region /region/] - Assert "laptop.tcl" wishes $::nodename shares statements like \ - [list "laptop.tcl" wishes to print /code/ with job id /jobid/] + } else { + source "lib/peer.tcl" + peer $::shareNode + + Assert "laptop.tcl" is providing root statements + Assert "laptop.tcl" wishes $::nodename shares statements like \ + [list "laptop.tcl" is providing root statements] + Assert "laptop.tcl" wishes $::nodename shares statements like \ + [list "laptop.tcl" claims /program/ has program code /code/] + Assert "laptop.tcl" wishes $::nodename shares statements like \ + [list "laptop.tcl" claims /program/ has region /region/] + Assert "laptop.tcl" wishes $::nodename shares statements like \ + [list "laptop.tcl" wishes to print /code/ with job id /jobid/] + } } Display::init diff --git a/lib/peer.tcl b/lib/peer.tcl index ca9c473a..e46017a0 100644 --- a/lib/peer.tcl +++ b/lib/peer.tcl @@ -1,8 +1,11 @@ +lappend auto_path "./vendor" +package require websocket + proc ::peer {node} { namespace eval Peers::$node { proc setupSock {} { variable node - puts "sharer: Trying to connect to: ws://$node:4273/ws" + puts "peer: Trying to connect to: ws://$node:4273/ws" variable sock [::websocket::open "ws://$node:4273/ws" [namespace code handleWs]] } proc handleWs {sock type msg} { @@ -26,10 +29,7 @@ proc ::peer {node} { ::websocket::send $sock text $msg } - proc init {n} { - variable node $n - setupSock - } + proc init {n} { variable node $n; setupSock } init } $node } diff --git a/lib/process.tcl b/lib/process.tcl index 1bca66da..5208384b 100644 --- a/lib/process.tcl +++ b/lib/process.tcl @@ -4,15 +4,16 @@ set ::processPrelude { try $body after $ms [list after idle [namespace code [info level 0]]] } - # TODO: do a socket connection to localhost - + + source "lib/peer.tcl" + peer "localhost" } proc On-process {name body} { namespace eval ::Processes::$name {} set ::Processes::${name}::name $name set ::Processes::${name}::body $body - set ::Processes::${name}::this [uplevel {set this}] + set ::Processes::${name}::this [uplevel {expr {[info exists this] ? $this : ""}}] namespace eval ::Processes::$name { variable tclfd [file tempfile tclfile tclfile.tcl] puts $tclfd [join [list $::processPrelude $body] "\n"]; close $tclfd @@ -28,6 +29,7 @@ proc On-process {name body} { variable log if {[gets $stdio line] >= 0} { lappend log $line + puts "$name: $line" Retract process $name has standard output log /l/ Assert process $name has standard output log $log Step @@ -36,7 +38,7 @@ proc On-process {name body} { fconfigure $stdio -blocking 0 -buffering line fileevent $stdio readable [namespace code handleReadable] - if {[info exists this]} { + if {$this ne ""} { Assert $this is running process $name } diff --git a/test/process.tcl b/test/process.tcl index d29b07e3..b0e5c01e 100644 --- a/test/process.tcl +++ b/test/process.tcl @@ -1,5 +1,4 @@ Assert when we are running { - set this T00 On process A { puts hello } @@ -7,10 +6,19 @@ Assert when we are running { Assert we are running Step -after 500 { - dict for {id stmt} $Statements::statements { puts [statement short $stmt] } +Assert when we are running { + On process { + Commit { Claim things are good } + } - exit 0 + When things are good { + set ::good true + } } +Step +after 500 { + if {[info exists ::good] && $::good} { exit 0 } \ + else { exit 1 } +} vwait forever -- cgit v1.2.3