Пример #1
0
func TestDaemon(t *testing.T) {

	daemon.New("127.0.0.1", 5558)

	c2 := daemon.NewClient("TESTID2", "127.0.0.1", "127.0.0.1", 5558, service.IMPORTING, ad1, []string{"192.168.137.1"}, []int{667})
	arrive2 := c2.Arrived().AsChan()
	c2.Run()
	time.Sleep(5 * time.Second)
	c1 := daemon.NewClient("TESTID1", "127.0.0.1", "127.0.0.1", 5558, service.EXPORTING, ad1, []string{"192.168.137.1"}, []int{666})
	c1.Run()

	select {
	case <-time.After(20 * time.Second):
		t.Fatal("export didnt arrive")
	case d := <-arrive2:
		r := d.(service.ServiceArrived)
		if r.UUID != "TESTID1" {
			t.Error("Wrong UUID", r.UUID, "TESTID1")
		}
		if r.Interface != "192.168.137.1" {
			t.Error("Wrong interface", r.Interface, "127.0.0.1")
		}
		if r.Port != 666 {
			t.Error("Wrong port", r.Port, 666)
		}
	}

}
Пример #2
0
func TestDaemonManyClients(t *testing.T) {

	var ads []string

	for i := 0; i < 2; i++ {
		ads = append(ads, fmt.Sprintf(
			`functions:
  - name: GetNrOfSamples%d
    output:
      - name: NrOfSamples
        type: int`, i))
	}

	daemon.New("127.0.0.1", 5558)

	var arrivials []chan eventual2go.Data

	for i, ad := range ads {
		c2 := daemon.NewClient(fmt.Sprintf("TESTID2%d", i), "127.0.0.1", "127.0.0.1", 5558, service.IMPORTING, ad, []string{"192.168.137.1"}, []int{697 + i})
		arrivials = append(arrivials, c2.Arrived().AsChan())
		c2.Run()
		time.Sleep(5 * time.Second)
		c1 := daemon.NewClient(fmt.Sprintf("TESTID1%d", i), "127.0.0.1", "127.0.0.1", 5558, service.EXPORTING, ad, []string{"192.168.137.1"}, []int{666 + i})
		c1.Run()
		time.Sleep(5 * time.Second)
	}

	for i, arrive := range arrivials {

		select {
		case <-time.After(10 * time.Second):
			t.Fatal("export didnt arrive", i)
		case d := <-arrive:
			r := d.(service.ServiceArrived)
			if r.UUID != fmt.Sprintf("TESTID1%d", i) {
				t.Error("Wrong UUID", r.UUID, fmt.Sprintf("TESTID1%d", i))
			}
			if r.Interface != "192.168.137.1" {
				t.Error("Wrong interface", r.Interface, "192.168.137.1")
			}
			if r.Port != 666+i {
				t.Error("Wrong port", r.Port, 666)
			}
		}
	}
}
Пример #3
0
func TestDaemon(t *testing.T) {
	daemon.New("127.0.0.1", 5558)
	ad := new(appdescriptor.AppDescriptor)

	c1 := daemon.NewClient("TESTID1", "127.0.0.1", "127.0.0.1", 5558, service.EXPORTING, ad, []string{"127.0.0.1:666"})
	arrive1 := c1.Arrived().AsChan()
	c1.Run()
	c2 := daemon.NewClient("TESTID2", "127.0.0.1", "127.0.0.1", 5558, service.IMPORTING, ad, []string{"127.0.0.1:667"})
	arrive2 := c2.Arrived().AsChan()
	c2.Run()
	select {
	case <-time.After(20 * time.Second):
		t.Fatal("import didnt arrive")
	case d := <-arrive1:
		r := d.(service.ServiceArrived)
		if r.UUID != "TESTID2" {
			t.Error("Wrong UUID", r.UUID, "TESTID2")
		}
		if r.Interface != "127.0.0.1" {
			t.Error("Wrong interface", r.Interface, "127.0.0.1")
		}
		if r.Port != 667 {
			t.Error("Wrong port", r.Port, 667)
		}
	}

	select {
	case <-time.After(2 * time.Second):
		t.Fatal("export didnt arrive")
	case d := <-arrive2:
		r := d.(service.ServiceArrived)
		if r.UUID != "TESTID1" {
			t.Error("Wrong UUID", r.UUID, "TESTID1")
		}
		if r.Interface != "127.0.0.1" {
			t.Error("Wrong interface", r.Interface, "127.0.0.1")
		}
		if r.Port != 666 {
			t.Error("Wrong port", r.Port, 666)
		}
	}

}