func TestClient_Send(t *testing.T) { local := sda.NewLocalTest() defer local.CloseAll() // register service sda.RegisterNewService("BackForth", func(c *sda.Context, path string) sda.Service { return &simpleService{ ctx: c, } }) // create hosts hosts, el, _ := local.GenTree(4, true, true, false) client := sda.NewClient("BackForth") r := &simpleRequest{ ServerIdentities: el, Val: 10, } nm, err := client.Send(hosts[0].ServerIdentity, r) log.ErrFatal(err) assert.Equal(t, nm.MsgType, simpleResponseType) resp := nm.Msg.(simpleResponse) assert.Equal(t, resp.Val, 10) }
func TestClient_Parallel(t *testing.T) { nbrNodes := 2 nbrParallel := 2 local := sda.NewLocalTest() defer local.CloseAll() // register service sda.RegisterNewService("BackForth", func(c *sda.Context, path string) sda.Service { return &simpleService{ ctx: c, } }) // create hosts hosts, el, _ := local.GenTree(nbrNodes, true, true, false) wg := sync.WaitGroup{} wg.Add(nbrParallel) for i := 0; i < nbrParallel; i++ { go func(i int) { log.Lvl1("Starting message", i) r := &simpleRequest{ ServerIdentities: el, Val: 10 * i, } client := sda.NewClient("BackForth") nm, err := client.Send(hosts[0].ServerIdentity, r) log.ErrFatal(err) assert.Equal(t, nm.MsgType, simpleResponseType) resp := nm.Msg.(simpleResponse) assert.Equal(t, resp.Val, 10*i) log.Lvl1("Done with message", i) wg.Done() }(i) } wg.Wait() }