func NewTaskListener(task domain.Task, e emitter.Emitter, logger *gosteno.Logger) *TaskListener { return &TaskListener{ Logger: logger, emitter: e, taskIdentifier: task.Identifier(), stdOutListener: loggingstream.NewLoggingStream(&task, logger, logmessage.LogMessage_OUT), stdErrListener: loggingstream.NewLoggingStream(&task, logger, logmessage.LogMessage_ERR), } }
BeforeEach(func() { tmpdir, _ := ioutil.TempDir("", "testing") task := &domain.Task{ ApplicationId: "1234", WardenJobId: 42, WardenContainerPath: tmpdir, Index: 1, SourceName: "App", } value := task.Identifier() os.MkdirAll(value, 0777) socketPath = filepath.Join(task.Identifier(), "stdout.sock") loggingStream = loggingstream.NewLoggingStream(task, loggertesthelper.Logger(), logmessage.LogMessage_OUT) loggertesthelper.TestLoggerSink.Clear() }) Describe("Listen", func() { It("should reconnect to the socket if it fails at startup", func(done Done) { testMessage := "a very nice test message" channel := loggingStream.Listen() go sendMessageToSocket(socketPath, testMessage) message := <-channel Expect(string(message.GetMessage())).To(Equal(testMessage)) logContents := loggertesthelper.TestLoggerSink.LogContents() Expect(string(logContents)).To(ContainSubstring("Could not read from socket OUT")) Eventually(func() string { return string(loggertesthelper.TestLoggerSink.LogContents()) }).Should(ContainSubstring("EOF while reading from socket OUT"))