13 func TestClient_testInterfaceReattach(t *testing.T) {
14 // Setup the process for daemonization
15 process := helperProcess("test-interface-daemon")
16 if process.SysProcAttr == nil {
17 process.SysProcAttr = &syscall.SysProcAttr{}
19 process.SysProcAttr.Setsid = true
22 c := NewClient(&ClientConfig{
24 HandshakeConfig: testHandshake,
25 Plugins: testPluginMap,
28 // Start it so we can get the reattach info
29 if _, err := c.Start(); err != nil {
30 t.Fatalf("err should be nil, got %s", err)
33 // New client with reattach info
34 reattach := c.ReattachConfig()
37 t.Fatal("reattach config should be non-nil")
40 // Find the process and defer a kill so we know it is gone
41 p, err := os.FindProcess(reattach.Pid)
44 t.Fatalf("couldn't find process: %s", err)
49 c = NewClient(&ClientConfig{
51 HandshakeConfig: testHandshake,
52 Plugins: testPluginMap,
55 // Start shouldn't error
56 if _, err := c.Start(); err != nil {
57 t.Fatalf("err: %s", err)
60 // It should still be alive
61 time.Sleep(1 * time.Second)
63 t.Fatal("should not be exited")
66 // Grab the RPC client
67 client, err := c.Client()
69 t.Fatalf("err should be nil, got %s", err)
73 raw, err := client.Dispense("test")
75 t.Fatalf("err should be nil, got %s", err)
78 impl, ok := raw.(testInterface)
80 t.Fatalf("bad: %#v", raw)
83 result := impl.Double(21)
85 t.Fatalf("bad: %#v", result)
88 // Test the resulting reattach config
89 reattach2 := c.ReattachConfig()
91 t.Fatal("reattach from reattached should not be nil")
93 if !reflect.DeepEqual(reattach, reattach2) {
94 t.Fatalf("bad: %#v", reattach)
100 // Test that it knows it is exited
102 t.Fatal("should say client has exited")