Esempio n. 1
0
func testCleanup(t *testing.T, g *graph.Graph, cmds []helper.Cmd, names []string) {
	// cleanup side on the test
	testPassed := false
	onChange := func(ws *websocket.Conn) {
		g.Lock()
		defer g.Unlock()

		if !testPassed {
			clean := true
			for _, name := range names {
				n := g.LookupFirstNode(graph.Metadata{"Name": name})
				if n != nil {
					clean = false
					break
				}
			}

			if clean {
				testPassed = true

				ws.Close()
			}
		}
	}

	testTopology(t, g, cmds, onChange)
	if !testPassed {
		t.Error("test not executed or failed")
	}

	helper.CleanGraph(g)
}
Esempio n. 2
0
func processGraphMessage(g *graph.Graph, m []byte) error {
	g.Lock()
	defer g.Unlock()

	var msg shttp.WSMessage
	if err := json.Unmarshal(m, &msg); err != nil {
		return err
	}

	if msg.Namespace != "Graph" {
		return nil
	}

	msgType, obj, err := graph.UnmarshalWSMessage(msg)
	if err != nil {
		return err
	}

	switch msgType {
	case "NodeUpdated":
		n := obj.(*graph.Node)
		node := g.GetNode(n.ID)
		if node != nil {
			g.SetMetadata(node, n.Metadata())
		}
	case "NodeDeleted":
		g.DelNode(obj.(*graph.Node))
	case "NodeAdded":
		n := obj.(*graph.Node)
		if g.GetNode(n.ID) == nil {
			g.AddNode(n)
		}
	case "EdgeUpdated":
		e := obj.(*graph.Edge)
		edge := g.GetEdge(e.ID)
		if edge != nil {
			g.SetMetadata(edge, e.Metadata())
		}
	case "EdgeDeleted":
		g.DelEdge(obj.(*graph.Edge))
	case "EdgeAdded":
		e := obj.(*graph.Edge)
		if g.GetEdge(e.ID) == nil {
			g.AddEdge(e)
		}
	}

	return nil
}
Esempio n. 3
0
func CleanGraph(g *graph.Graph) {
	g.Lock()
	defer g.Unlock()
	hostname, _ := os.Hostname()
	g.DelHostGraph(hostname)
}