Skip to content

Commit

Permalink
wait for the right things...
Browse files Browse the repository at this point in the history
  • Loading branch information
jackyzha0 committed Jun 6, 2024
1 parent 23b6009 commit 627c699
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
10 changes: 1 addition & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,7 @@ impl Pty {
#[allow(dead_code)]
pub fn fd(&mut self) -> Result<c_int, napi::Error> {
if let Some(fd) = &self.controller_fd {
let res = unsafe { libc::fcntl(fd.as_raw_fd(), libc::F_DUPFD_CLOEXEC, 3) };
if res == -1 {
return Err(napi::Error::new(
napi::Status::GenericFailure,
format!("fcntl F_DUPFD_CLOEXEC failed: {}", Error::last_os_error()),
));
}

Ok(res)
Ok(fd.as_raw_fd())
} else {
Err(napi::Error::new(
napi::Status::GenericFailure,
Expand Down
18 changes: 9 additions & 9 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function getOpenFds(): FdRecord {
for (const filename of readdirSync(procSelfFd)) {
try {
const linkTarget = readlinkSync(procSelfFd + filename);
if (linkTarget === 'anon_inode:[timerfd]') {
if (linkTarget === 'anon_inode:[timerfd]' || linkTarget.startsWith("socket:[")) {
continue;
}

Expand Down Expand Up @@ -72,7 +72,7 @@ describe('PTY', () => {
onExit: async (err, exitCode) => {
expect(err).toBeNull();
expect(exitCode).toBe(0);
vi.waitFor(() => expect(buffer.trim()).toBe(message));
await vi.waitFor(() => expect(buffer.trim()).toBe(message));
done();
},
});
Expand Down Expand Up @@ -109,8 +109,8 @@ describe('PTY', () => {

pty = new Pty({
command: '/bin/cat',
onExit: () => {
vi.waitFor(() => expect(buffer.trim()).toBe(result.trim()));
onExit: async () => {
await vi.waitFor(() => expect(buffer.trim()).toBe(result.trim()));
done();
},
});
Expand Down Expand Up @@ -169,10 +169,10 @@ describe('PTY', () => {
pty = new Pty({
command: '/bin/pwd',
dir: cwd,
onExit: (err, exitCode) => {
onExit: async (err, exitCode) => {
expect(err).toBeNull();
expect(exitCode).toBe(0);
vi.waitFor(() => expect(buffer.trim()).toBe(cwd));
await vi.waitFor(() => expect(buffer.trim()).toBe(cwd));

done();
},
Expand All @@ -195,10 +195,10 @@ describe('PTY', () => {
envs: {
ENV_VARIABLE: message,
},
onExit: (err, exitCode) => {
onExit: async (err, exitCode) => {
expect(err).toBeNull();
expect(exitCode).toBe(0);
vi.waitFor(() => expect(buffer.trim()).toBe(message));
await vi.waitFor(() => expect(buffer.trim()).toBe(message));

done();
},
Expand All @@ -223,4 +223,4 @@ describe('PTY', () => {
done();
}
}));
}, { repeats: 1 });
}, { repeats: 15 });

0 comments on commit 627c699

Please sign in to comment.