Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Unified Diff: client/internal/logdog/butler/streamserver/namedPipe_posix_test.go

Issue 1429993002: LogDog: Add Butler stream server package. (Closed) Base URL: https://github.com/luci/luci-go@logdog-review-butlerproto
Patch Set: Bind POSIX test to POSIX domains. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: client/internal/logdog/butler/streamserver/namedPipe_posix_test.go
diff --git a/client/internal/logdog/butler/streamserver/namedPipe_posix_test.go b/client/internal/logdog/butler/streamserver/namedPipe_posix_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..0b76498144837090b1caef3807c4d5336bb8708f
--- /dev/null
+++ b/client/internal/logdog/butler/streamserver/namedPipe_posix_test.go
@@ -0,0 +1,76 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// +build darwin dragonfly freebsd linux netbsd openbsd
+
+package streamserver
+
+import (
+ "io"
+ "io/ioutil"
+ "net"
+ "os"
+ "path/filepath"
+ "testing"
+
+ "golang.org/x/net/context"
+)
+
+type posixNamedPipeTester struct {
+ t *testing.T
+}
+
+// Decorates a test function with a NamedPipeServer serving from a temporary
+// path.
+func (npt *posixNamedPipeTester) withServer(f func(i *namedPipeTestInstance)) func() {
+ return func() {
+ // Create a temporary testing directory.
+ tempdir, err := ioutil.TempDir(os.TempDir(), "named_pipe_posix_test")
+ if err != nil {
+ panic("Failed to create testing temporary directory.")
+ }
+ defer func() {
+ // Cleanup the temporary directory.
+ os.RemoveAll(tempdir)
+ }()
+
+ path := filepath.Join(tempdir, "butler.sock")
+ s := NewNamedPipeServer(context.Background(), path).(*namedPipeServer)
+ npt.t.Logf("Created testing server for: %s", path)
+
+ // Start listening.
+ err = s.Listen()
+ if err != nil {
+ panic("Failed to listen on server instance.")
+ }
+ defer func() {
+ // Close the server. Some of our tests might mess with this, so check
+ // first to make sure it's still open.
+ if s.l != nil {
+ s.Close()
+ }
+ }()
+
+ // goroutine-safe connection creation.
+ inst := &namedPipeTestInstance{
+ S: s,
+ connect: func() io.WriteCloser {
+ npt.t.Logf("Connecting to testing server at: %s", path)
+ conn, err := net.Dial("unix", path)
+ if err != nil {
+ npt.t.Logf("Failed to connect client instance: %s", err)
+ return nil
+ }
+ return conn
+ },
+ }
+
+ // Execute the function using this valid server!
+ f(inst)
+ }
+}
+
+func TestNamedPipeServer(t *testing.T) {
+ testNamedPipeServer(t, &posixNamedPipeTester{t})
+}

Powered by Google App Engine
This is Rietveld 408576698