mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-26 03:25:35 +00:00
adc5997592
This starts to refactor tsdial.Dialer's name resolution to have different stages: in-memory MagicDNS vs system resolution. A future change will plug in ExitDNS resolution. This also plumbs a Dialer into netstack and unexports the dnsMap internals. And it removes some of the async AddNetworkMapCallback usage and replaces it with synchronous updates of the Dialer's netmap from LocalBackend, since the LocalBackend has the Dialer too. Updates #3475 Change-Id: Idcb7b1169878c74f0522f5151031ccbc49fe4cb4 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
79 lines
1.8 KiB
Go
79 lines
1.8 KiB
Go
// Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package ipnserver_test
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"tailscale.com/ipn"
|
|
"tailscale.com/ipn/ipnserver"
|
|
"tailscale.com/net/tsdial"
|
|
"tailscale.com/safesocket"
|
|
"tailscale.com/wgengine"
|
|
)
|
|
|
|
func TestRunMultipleAccepts(t *testing.T) {
|
|
t.Skipf("TODO(bradfitz): finish this test, once other fires are out")
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
|
|
td := t.TempDir()
|
|
socketPath := filepath.Join(td, "tailscale.sock")
|
|
|
|
logf := func(format string, args ...interface{}) {
|
|
format = strings.TrimRight(format, "\n")
|
|
println(fmt.Sprintf(format, args...))
|
|
t.Logf(format, args...)
|
|
}
|
|
|
|
connect := func() {
|
|
for i := 1; i <= 2; i++ {
|
|
logf("connect %d ...", i)
|
|
c, err := safesocket.Connect(socketPath, 0)
|
|
if err != nil {
|
|
t.Fatalf("safesocket.Connect: %v\n", err)
|
|
}
|
|
clientToServer := func(b []byte) {
|
|
ipn.WriteMsg(c, b)
|
|
}
|
|
bc := ipn.NewBackendClient(logf, clientToServer)
|
|
prefs := ipn.NewPrefs()
|
|
bc.SetPrefs(prefs)
|
|
c.Close()
|
|
}
|
|
}
|
|
|
|
logTriggerTestf := func(format string, args ...interface{}) {
|
|
logf(format, args...)
|
|
if strings.HasPrefix(format, "Listening on ") {
|
|
connect()
|
|
}
|
|
}
|
|
|
|
eng, err := wgengine.NewFakeUserspaceEngine(logf, 0)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Cleanup(eng.Close)
|
|
|
|
opts := ipnserver.Options{}
|
|
t.Logf("pre-Run")
|
|
store := new(ipn.MemoryStore)
|
|
|
|
ln, _, err := safesocket.Listen(socketPath, 0)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer ln.Close()
|
|
|
|
err = ipnserver.Run(ctx, logTriggerTestf, ln, store, nil /* mon */, new(tsdial.Dialer), "dummy_logid", ipnserver.FixedEngine(eng), opts)
|
|
t.Logf("ipnserver.Run = %v", err)
|
|
}
|