Skip to content

Commit

Permalink
feat: update test
Browse files Browse the repository at this point in the history
  • Loading branch information
akitaSummer committed Feb 29, 2024
1 parent 4231372 commit d8a8521
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 103 deletions.
1 change: 1 addition & 0 deletions .mocharc-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ require:
- intelli-espower-loader
full-trace: true
exit: true
parallel: false
1 change: 1 addition & 0 deletions .mocharc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ require:
- intelli-espower-loader
full-trace: true
exit: true
parallel: false
5 changes: 5 additions & 0 deletions integration/fixtures/not-exist-lock-file/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"canvas": "2.9.0"
}
}
57 changes: 0 additions & 57 deletions integration/fixtures/utils/pids.js

This file was deleted.

19 changes: 13 additions & 6 deletions integration/index.2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,25 @@ describe('test/index.v2.test.js', () => {
let cwd;

afterEach(async () => {
await clean({ cwd });
try {
await clean({ cwd, daemon: true });
} catch (e) {
console.warn('clean error: ', e);
}
if (process.platform === 'darwin') {
try {
await forceExitDaemon();
} catch (err) {
console.warn('force exit daemon error: %s', err.message);
}
} else {
await exitDaemon();
try {
await exitDaemon();
} catch (err) {
console.warn('exit daemon error: %s', err.message);
}
}

});

describe('update', () => {
Expand Down Expand Up @@ -223,9 +232,8 @@ describe('test/index.v2.test.js', () => {
assert.strictEqual(dirs.filter(dir => dir.includes('esbuild')).length, 2);
await assert.doesNotReject(fs.stat(path.join(cwd, 'node_modules/esbuild')));
assert.strictEqual(require(path.join(cwd, 'node_modules', 'esbuild/package.json')).version, '0.15.14');
const nodeModulesDir = path.join(cwd, 'node_modules');

await execa.command(`umount -f ${nodeModulesDir}`);
await execa.command('killall -9 nydusd');
await setTimeoutPromise(20000);
assert.strictEqual(require(path.join(cwd, 'node_modules', 'esbuild/package.json')).version, '0.15.14');
});
Expand All @@ -248,9 +256,8 @@ describe('test/index.v2.test.js', () => {
assert.strictEqual(dirs.filter(dir => dir.includes('esbuild')).length, 2);
await assert.doesNotReject(fs.stat(path.join(cwd, 'node_modules/esbuild')));
assert.strictEqual(require(path.join(cwd, 'node_modules', 'esbuild/package.json')).version, '0.15.14');
const nodeModulesDir = path.join(cwd, 'node_modules');

await execa.command(`umount -f ${nodeModulesDir}`);
await execa.command('killall -9 nydusd');
await setTimeoutPromise(20000);

await assert.rejects(fs.stat(path.join(cwd, 'node_modules', 'esbuild/package.json')));
Expand Down
10 changes: 7 additions & 3 deletions integration/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ const {
describe('test/index.test.js', () => {
let fixture;
afterEach(async () => {
await clean({
cwd: fixture,
});
try {
await clean({
cwd: fixture,
});
} catch (e) {
console.warn('clean error: ', e);
}
if (process.platform === 'darwin') {
await forceExitDaemon();
} else {
Expand Down
12 changes: 8 additions & 4 deletions integration/workspaces.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ describe('test/workspaces.test.js', () => {

it('should install lodash successfully', async () => {
cwd = path.join(__dirname, './fixtures/workspaces');
await clean({
cwd,
force: true,
});
try {
await clean({
cwd,
force: true,
});
} catch (e) {
console.warn('clean error: ', e);
}
await install({
nydusMode: 'FUSE',
cwd,
Expand Down
13 changes: 3 additions & 10 deletions packages/cli/lib/nydusd/nydusd_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ async function checkDaemon() {
// 优雅退出 nydusd daemon
async function exitDaemon() {
try {
await killDeamon();
await urllib.request(`${daemonUrl}/exit`, {
method: 'PUT',
socketPath,
dataType: 'json',
});
await killDeamon();
} catch (e) {
// ignore, nydusd quits with error, but it's ok
e.message = 'exit nydusd faield: ' + e.message;
Expand All @@ -170,15 +170,6 @@ async function forceExitDaemon() {
e.message = 'umount nydusd mnt failed: ' + e.message;
console.warn(e);
}

try {
await killDeamon();
await execa.command('killall -9 nydusd');
} catch (e) {
// ignore, nydusd quits with error, but it's ok
e.message = 'exit nydusd failed: ' + e.message;
console.warn(e);
}
}

async function mount(mountpoint, cwd, bootstrap = '') {
Expand Down Expand Up @@ -218,6 +209,8 @@ async function mount(mountpoint, cwd, bootstrap = '') {
});
debug('mount result: %j', result);

await new Promise(resolve => setTimeout(resolve, 1000));

return config;
}

Expand Down
14 changes: 4 additions & 10 deletions packages/cli/test/package_lock.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ const path = require('node:path');
const fs = require('node:fs/promises');
const mm = require('mm');
const PackageLock = require('../lib/package_lock').PackageLock;
const { install } = require('../lib');
const httpclient = require('../lib/httpclient');
const { generatePackageLock } = require('../lib/util');
const nydusd = require('../lib/nydusd');
const downloadDependency = require('../lib/download_dependency');

Expand Down Expand Up @@ -68,15 +67,10 @@ describe('test/package_lock.test.js', () => {
mm.restore();
});

it('should run all project installation scripts', async () => {
it('should generate package-lock.json', async () => {
fixture = path.join(__dirname, './fixtures/not-exist-lock-file');
const pkg = require(path.join(fixture, 'package.json'));
await install({
httpclient,
pkg,
cwd: fixture,
console: global.console,
});

await generatePackageLock(fixture);
await fs.stat(path.join(fixture, 'package-lock.json'));
});
});
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/test/scripts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ describe('test/scripts.test.js', () => {
mm(process.env, NYDUS_CSI_ROOT_ENV, 'true');
mm(process, 'cwd', () => fixtures);
mm(nydusd, 'startNydusFs', async () => { });
mm(util, 'ensureAccess', async () => { });
mm(util, 'storePackageLock', async () => { });
mm(downloadDependency, 'download', async () => {
return {
depsTree: [ 1 ],
Expand Down
50 changes: 37 additions & 13 deletions packages/deamon/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use log::{error, info};
use regex::Regex;
use serde::{Deserialize, Serialize};
use serde_json::Error;
use std::{path::PathBuf, process::Command};
use std::os::unix::fs::PermissionsExt;
use std::{path::PathBuf, process::Command};

use crate::utils::{del_dir_if_exists, get_ps_snapshot, start_command, create_dir_if_not_exists};
use crate::utils::{create_dir_if_not_exists, del_dir_if_exists, get_ps_snapshot, start_command};

// {
// projectName: "",
Expand Down Expand Up @@ -59,7 +59,6 @@ pub struct NydusdConfig {
overlay: Option<NydusdOverlayConfig>,
}


#[derive(Debug, Deserialize, Serialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub struct NydusdOverlayConfig {
Expand Down Expand Up @@ -120,28 +119,46 @@ impl NydusdApiMount {
let homedir = get_my_home()?;

let base = match homedir {
Some(home) => home.join(".rapid/cache/mnt").join(self.mountpoint.clone()).to_string_lossy().to_string(),
None => return Err(anyhow!("Error executing link_node_modules: get home path false")),
Some(home) => home
.join(".rapid/cache/mnt")
.join(self.mountpoint.clone())
.to_string_lossy()
.to_string(),
None => {
return Err(anyhow!(
"Error executing link_node_modules: get home path false"
))
}
};

let str = format!(r#"ln -s {} {}"#, base, self.node_modules_dir);
match start_command(&str) {
Ok(output) => {
if output.status.success() {
info!("link_node_modules success base {} target {}", base, self.node_modules_dir);
info!(
"link_node_modules success base {} target {}",
base, self.node_modules_dir
);
return Ok(());
} else {
return Err(anyhow!(
"Error executing link_node_modules, status: {:?}, stdout: {:?}, stderr: {:?}, base {}, target {}",
output.status,
std::str::from_utf8(&output.stdout)?,
std::str::from_utf8(&output.stderr)?,
base,
std::str::from_utf8(&output.stderr)?,
base,
self.node_modules_dir,
));
}
}
Err(e) => return Err(anyhow!("Error executing link_node_modules: {:?}, base {}, target {}", e, base, self.node_modules_dir)),
Err(e) => {
return Err(anyhow!(
"Error executing link_node_modules: {:?}, base {}, target {}",
e,
base,
self.node_modules_dir
))
}
}
}

Expand Down Expand Up @@ -327,9 +344,13 @@ impl Overlay {
create_dir_if_not_exists(self.overlay.clone())?;
create_dir_if_not_exists(self.upper.clone())?;
create_dir_if_not_exists(self.workdir.clone())?;
std::fs::metadata(&self.upper)?.permissions().set_mode(0o777);
std::fs::metadata(&self.workdir)?.permissions().set_mode(0o777);

std::fs::metadata(&self.upper)?
.permissions()
.set_mode(0o777);
std::fs::metadata(&self.workdir)?
.permissions()
.set_mode(0o777);

Ok(())
}
}
Expand Down Expand Up @@ -405,7 +426,10 @@ impl ProjectConfig {
}

pub fn get_node_modules_paths(&self) -> Vec<String> {
self.nydusd_api_mount.iter().map(|c| c.node_modules_dir.clone()).collect()
self.nydusd_api_mount
.iter()
.map(|c| c.node_modules_dir.clone())
.collect()
}

pub fn get_pids(&self) -> Result<Vec<u32>> {
Expand Down

0 comments on commit d8a8521

Please sign in to comment.