Skip to content

Commit

Permalink
Old in-progress change.
Browse files Browse the repository at this point in the history
  • Loading branch information
mstone committed Jan 1, 2016
1 parent f12edda commit 452882f
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 17 deletions.
2 changes: 2 additions & 0 deletions client/client.go
Expand Up @@ -81,6 +81,8 @@ func makeDocument(sessionObj *js.Object, docObj **js.Object) (built bool, err er
}

func main() {
// js.Debugger()

var built bool
var err error
var aceDiv *js.Object
Expand Down
37 changes: 37 additions & 0 deletions docs/notes/testing.txt
@@ -0,0 +1,37 @@
= focus(1) Testing
Michael Stone <mistone@akamai.com>
v0.1, 2015-11-01
:toc:
:homepage: http://github.com/mstone/focus
:numbered:
:sectlinks:
:icons: font

ifdef::env-github[:outfilesuffix: .adoc]


== Problem

focus needs automated client-side tests, particularly to check the integration between ACE, web-sockets, the connection controller, and the VPP server.

Secondarily, we should also think about testing browser compatibility.

== Situation




== Options

Sauce Labs 'Open Sauce'.

Selenium WebDriver + Selenium Server

casperjs

zombie.js

jsdom



22 changes: 17 additions & 5 deletions js/alert/alert.go
Expand Up @@ -10,15 +10,27 @@ import (
)

func Golang(s interface{}) {
js.Global.Get("console").Call("log", fmt.Sprintf("%+v", s))
if js.Global == nil {
fmt.Printf("%+v\n", s)
} else {
js.Global.Get("console").Call("log", fmt.Sprintf("%+v", s))
}
}

func String(s string) {
js.Global.Get("console").Call("log", s)
if js.Global == nil {
fmt.Printf("%s\n", s)
} else {
js.Global.Get("console").Call("log", s)
}
}

func JSON(o *js.Object) {
s := o.String()
// js.Global.Get("JSON").Call("stringify", o).String()
js.Global.Get("console").Call("log", s)
if js.Global == nil {
fmt.Printf("%s\n", o.String())
} else {
s := o.String()
// js.Global.Get("JSON").Call("stringify", o).String()
js.Global.Get("console").Call("log", s)
}
}
5 changes: 3 additions & 2 deletions main.go
Expand Up @@ -21,8 +21,9 @@ import (
"github.com/mstone/focus/store"
)

//go:generate gopherjs build github.com/mstone/focus/client -m -o public/client.js
//go:generate esc -o assets.go -pkg=main -prefix=public/ public/client.js public/ace-builds/src-min-noconflict/
//go:generate gopherjs build github.com/mstone/focus/client -o public/client.js
//go:generate sed -i -e s,\"/,\"http://localhost:8080/,g public/client.js.map
//go:generate esc -o assets.go -pkg=main -prefix=public/ public/client.js public/client.js.map public/ace-builds/src-min-noconflict/
//go:generate go-bindata -o bindata.go -prefix=templates/ templates/

func main() {
Expand Down
32 changes: 27 additions & 5 deletions ot/ot.go
Expand Up @@ -87,7 +87,6 @@ func Apply(o Op, t *Tree) error {

tz := NewZipper(t, 0, 10)

// olen := len(o.Kids)
for _, o := range o.Kids {
switch {
case o.IsZero():
Expand All @@ -100,10 +99,27 @@ func Apply(o Op, t *Tree) error {
case o.IsDelete():
tz.Delete(o.Len())
case o.IsWith():
err := Apply(o, tz.Current())
// BUG(mistone): on a newly created zipper to a Branch(nil), tz.Current is nil
// because our zipper is an insertion-point, at index 0, to the left of cell
// #0 in t.Kids (bug?).
//
// However, as we advance down into t, we will create new zippers each time
// we descend (bug?). Therefore, for the purposes of applying a top-level With-op, we
// want to recurse on tz.Parent()
//
// However, assuming we're already in the middle of processing, current will correctly
// point to the branch to be modified.
//
// (Argh!)
c := tz.Current()
// if c == nil {
// c = tz.Parent()
// }
err := Apply(o, c)
if err != nil {
return errors.Trace(err)
}
tz.Skip(1)
}
}
return nil
Expand Down Expand Up @@ -506,16 +522,19 @@ func (d *Doc) String() string {
return d.body.String()
}

func (d *Doc) Apply(os Ops) {
func (d *Doc) Apply(os Ops) error {
d.mu.Lock()
defer d.mu.Unlock()

body := d.body.Clone()
// alert.String(fmt.Sprintf("Apply: ops: %s, body: %+v", os.String(), body))

err := Apply(W(os), &body)
if err != nil {
panic(err)
return errors.Trace(err)
}
d.body = body
return nil
}

func RandIntn(n int) int {
Expand Down Expand Up @@ -757,7 +776,10 @@ func (c *Controller) OnServerAck(rev int, ops Ops) {
}

func (c *Controller) OnServerWrite(rev int, ops Ops) {
c.serverDoc.Apply(ops)
err := c.serverDoc.Apply(ops)
if err != nil {
panic(err)
}
switch c.state {
case CS_SYNCED:
c.serverRev = rev
Expand Down
7 changes: 5 additions & 2 deletions ot/tree.go
Expand Up @@ -42,8 +42,10 @@ func (ts Trees) Clone() Trees {
return ret
}

func (t Tree) String() string {
func (t *Tree) String() string {
switch {
case t == nil:
return "nil"
case t.Tag == T_LEAF:
return AsString([]rune{t.Leaf})
case t.Tag == T_BRANCH:
Expand Down Expand Up @@ -209,8 +211,9 @@ func (z *Zipper) Current() *Tree {
p, n := z.Parent(), z.Index()
if 0 <= n && n < len(p.Kids) {
return &z.Parent().Kids[z.Index()]
} else {
return z.Parent()
}
return nil
}

func (z *Zipper) Parent() *Tree {
Expand Down
6 changes: 3 additions & 3 deletions ot/tree_test.go
Expand Up @@ -17,7 +17,7 @@ func TestZipperInsert(t *testing.T) {
t.Fatalf("index != 0")
}

if z.Current() != nil {
if z.Current() != &root {
t.Fatalf("current != nil")
}

Expand Down Expand Up @@ -54,7 +54,7 @@ func TestZipperInsert(t *testing.T) {

z.Delete(1)

// back to square emtpy root
// back to square empty root
if z.Parent() != &root {
t.Fatalf("parent != root")
}
Expand All @@ -63,7 +63,7 @@ func TestZipperInsert(t *testing.T) {
t.Fatalf("index != 0")
}

if z.Current() != nil {
if z.Current() != &root {
t.Fatalf("current != nil")
}

Expand Down
1 change: 1 addition & 0 deletions server/server.go
Expand Up @@ -83,6 +83,7 @@ func (s *Server) configure() error {
m.Use(negroni.HandlerFunc(func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
log.Info("http request", "req", r)
next(w, r)
log.Info("http response", "resp", w)
}))
m.Use(negroni.HandlerFunc(func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
defer func() {
Expand Down

0 comments on commit 452882f

Please sign in to comment.