This repository was archived by the owner on Nov 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 200
Actively tail worker stdio from supervisor agent #588
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
12ac7c0
Don't pipe worker stdio to supervisor agent
ranweiler b9324b0
Lint
ranweiler 7af8cfd
Revert
ranweiler 43acdab
Read from worker agent output streams in background threads
ranweiler 2876339
Format
ranweiler 0c57a6c
Merge branch 'main' into worker-stdio
bmc-msft 997ac08
Merge branch 'main' into worker-stdio
bmc-msft c9e929d
Rename to `TailBuffer`, add tests
ranweiler 7ae1107
Directly spawn redirected child from command
ranweiler ae91cfc
Break on EOF
ranweiler 7d8f719
Add Linux test for `RedirectedChild`
ranweiler b5521aa
Format
ranweiler 9ce2eeb
Fix test readability
ranweiler e7b55d0
Merge branch 'main' into worker-stdio
bmc-msft 27de693
Merge branch 'main' into worker-stdio
bmc-msft b321ddf
Add child redirection test for Windows
ranweiler fc0b5f1
Merge branch 'main' into worker-stdio
ranweiler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
#[derive(Clone, Debug, Eq, PartialEq)] | ||
pub struct TailBuffer { | ||
data: Vec<u8>, | ||
capacity: usize, | ||
} | ||
|
||
impl TailBuffer { | ||
pub fn new(capacity: usize) -> Self { | ||
let data = Vec::with_capacity(capacity); | ||
Self { data, capacity } | ||
} | ||
|
||
pub fn data(&self) -> &[u8] { | ||
&self.data | ||
} | ||
|
||
pub fn to_string_lossy(&self) -> String { | ||
String::from_utf8_lossy(self.data()).to_string() | ||
} | ||
} | ||
|
||
impl std::io::Write for TailBuffer { | ||
fn write(&mut self, new_data: &[u8]) -> std::io::Result<usize> { | ||
// Write the new data to the internal buffer, allocating internally as needed. | ||
self.data.extend(new_data); | ||
|
||
// Shift and truncate the buffer if it is too big. | ||
if self.data.len() > self.capacity { | ||
let lo = self.data.len() - self.capacity; | ||
let range = lo..self.data.len(); | ||
self.data.copy_within(range, 0); | ||
self.data.truncate(self.capacity); | ||
} | ||
|
||
Ok(new_data.len()) | ||
} | ||
|
||
fn flush(&mut self) -> std::io::Result<()> { | ||
Ok(()) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use std::io::Write; | ||
|
||
use super::*; | ||
|
||
#[test] | ||
fn test_tail_buffer() { | ||
let mut buf = TailBuffer::new(5); | ||
|
||
assert!(buf.data().is_empty()); | ||
|
||
buf.write(&[1, 2, 3]).unwrap(); | ||
assert_eq!(buf.data(), &[1, 2, 3]); | ||
|
||
buf.write(&[]).unwrap(); | ||
assert_eq!(buf.data(), &[1, 2, 3]); | ||
|
||
buf.write(&[4, 5]).unwrap(); | ||
assert_eq!(buf.data(), &[1, 2, 3, 4, 5]); | ||
|
||
buf.write(&[6, 7, 8]).unwrap(); | ||
assert_eq!(buf.data(), &[4, 5, 6, 7, 8]); | ||
|
||
buf.write(&[9, 10, 11, 12, 13]).unwrap(); | ||
assert_eq!(buf.data(), &[9, 10, 11, 12, 13]); | ||
|
||
buf.write(&[14, 15, 16, 17, 18, 19, 20, 21, 22]).unwrap(); | ||
assert_eq!(buf.data(), &[18, 19, 20, 21, 22]); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.