4107733453
* PoC: memory registry using maps instead of slice madness * Updated proto and handlers. Fixed tests across codebase. * Implemented ttl pruning for memory registry * Added extensive memory registry tests * Squased a bunch of bugs * Proto indent; memory.Registry.String() returns "memory" * Write a test to prove memory registry TTLs are busted Signed-off-by: Erik Hollensbe <github@hollensbe.org> * Additional memory testing and fixups: * DefaultTTL removed * When TTL == 0, it is automatically removed from expiry conditions * Additional improvements to new tests Signed-off-by: Erik Hollensbe <github@hollensbe.org>
63 lines
969 B
Go
63 lines
969 B
Go
package micro
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
"testing"
|
|
|
|
proto "github.com/micro/go-micro/debug/proto"
|
|
"github.com/micro/go-micro/registry/memory"
|
|
)
|
|
|
|
func TestFunction(t *testing.T) {
|
|
var wg sync.WaitGroup
|
|
wg.Add(1)
|
|
|
|
r := memory.NewRegistry(memory.Services(testData))
|
|
|
|
// create service
|
|
fn := NewFunction(
|
|
Registry(r),
|
|
Name("test.function"),
|
|
AfterStart(func() error {
|
|
wg.Done()
|
|
return nil
|
|
}),
|
|
)
|
|
|
|
// we can't test fn.Init as it parses the command line
|
|
// fn.Init()
|
|
|
|
ch := make(chan error, 2)
|
|
|
|
go func() {
|
|
// run service
|
|
ch <- fn.Run()
|
|
}()
|
|
|
|
// wait for start
|
|
wg.Wait()
|
|
|
|
// test call debug
|
|
req := fn.Client().NewRequest(
|
|
"test.function",
|
|
"Debug.Health",
|
|
new(proto.HealthRequest),
|
|
)
|
|
|
|
rsp := new(proto.HealthResponse)
|
|
|
|
err := fn.Client().Call(context.TODO(), req, rsp)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if rsp.Status != "ok" {
|
|
t.Fatalf("function response: %s", rsp.Status)
|
|
}
|
|
|
|
if err := <-ch; err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|