Ejemplo n.º 1
0
func TestThatWeRetryListeningToStdErrUnixSocket(t *testing.T) {
	task, tmpdir := setupTask(t, 3)
	defer os.RemoveAll(tmpdir)

	stdoutSocketPath := filepath.Join(task.identifier(), "stdout.sock")
	stderrSocketPath := filepath.Join(task.identifier(), "stderr.sock")
	loggerPath := filepath.Join(tmpdir, "logger")
	os.Remove(stdoutSocketPath)
	os.Remove(stderrSocketPath)
	os.Remove(loggerPath)

	receiveChannel := setupEmitter(t, task, loggertesthelper.FileLogger(loggerPath))

	go func() {
		time.Sleep(950 * time.Millisecond)
		stderrListener, err := net.Listen("unix", stderrSocketPath)
		defer stderrListener.Close()
		assert.NoError(t, err)
		connection, err := stderrListener.Accept()
		defer connection.Close()
		assert.NoError(t, err)
		_, err = connection.Write([]byte(SOCKET_PREFIX + "Error Message!!!"))
	}()

	select {
	case receivedMessage := <-receiveChannel:
		assert.Contains(t, string(receivedMessage.GetMessage()), "Error Message!!!")
	case <-time.After(3 * time.Second):
		t.Error("Timed out waiting for message")
	}

	logContents, err := ioutil.ReadFile(loggerPath)
	assert.NoError(t, err)
	assert.Contains(t, string(logContents), "Error while dialing into socket ERR")
}
Ejemplo n.º 2
0
func TestThatWeRetryListeningToStdErrUnixSocket(t *testing.T) {
	tmpdir, err := ioutil.TempDir("", "testing")
	assert.NoError(t, err)
	defer os.RemoveAll(tmpdir)

	instance := &instance{
		applicationId:       "1234",
		wardenJobId:         56,
		wardenContainerPath: tmpdir,
		index:               3,
		drainUrls:           []string{"syslog://10.20.30.40:8050"},
	}

	os.MkdirAll(instance.identifier(), 0777)

	stdoutSocketPath := filepath.Join(instance.identifier(), "stdout.sock")
	stderrSocketPath := filepath.Join(instance.identifier(), "stderr.sock")
	loggerPath := filepath.Join(tmpdir, "logger")
	os.Remove(stdoutSocketPath)
	os.Remove(stderrSocketPath)
	os.Remove(loggerPath)

	mockLoggregatorEmitter := new(MockLoggregatorEmitter)

	mockLoggregatorEmitter.received = make(chan *logmessage.LogMessage)

	instance.startListening(mockLoggregatorEmitter, loggertesthelper.FileLogger(loggerPath))

	go func() {
		time.Sleep(950 * time.Millisecond)
		stderrListener, err := net.Listen("unix", stderrSocketPath)
		defer stderrListener.Close()
		assert.NoError(t, err)
		connection, err := stderrListener.Accept()
		defer connection.Close()
		assert.NoError(t, err)
		_, err = connection.Write([]byte("Error Message!!!"))
	}()

	select {
	case receivedMessage := <-mockLoggregatorEmitter.received:
		assert.Contains(t, string(receivedMessage.GetMessage()), "Error Message!!!")
	case <-time.After(3 * time.Second):
		t.Error("Timed out waiting for message")
	}

	logContents, err := ioutil.ReadFile(loggerPath)
	assert.NoError(t, err)
	assert.Contains(t, string(logContents), "Error while dialing into socket ERR")
}