我正在Windows10 WSL2上测试一个Rails项目。我可以毫无问题地运行rails server
,但是当我运行rails test test/integration
时,我得到了NotImplementedError: fork() function is unimplemented on this machine
错误
Ruby版本:ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
Rails版本:Rails 5.2.0
Ubuntu: 20.04
发布于 2020-06-16 14:27:45
在这台documentation上,据说
fork(2)在某些平台上不可用,如NetBSD和Windows4。因此,您应该使用()而不是fork()。
所以你要测试的gem正在尝试调用这个函数。您需要在文本编辑器中打开ruby gem,并将编写脚本的位置更改为fork()函数,将其替换为()。从这个开始:
static VALUE
rb_f_fork(VALUE obj)
{
rb_pid_t pid;
switch (pid = rb_fork_ruby(NULL)) {
case 0:
rb_thread_atfork();
if (rb_block_given_p()) {
int status;
rb_protect(rb_yield, Qundef, &status);
ruby_stop(status);
}
return Qnil;
case -1:
rb_sys_fail("fork(2)");
return Qnil;
default:
return PIDT2NUM(pid);
}
}
到这个
static VALUE
rb_f_fork(VALUE obj)
{
rb_pid_t pid;
switch (pid = rb_fork_ruby(NULL)) {
case 0:
rb_thread_atfork();
if (rb_block_given_p()) {
int status;
rb_protect(rb_yield, Qundef, &status);
ruby_stop(status);
}
return Qnil;
case -1:
rb_sys_fail("spawn(2)");
return Qnil;
default:
return PIDT2NUM(pid);
}
}
或者,您可以在windows环境中维护rails应用程序的单独副本来测试集成:从github克隆它
git clone <the path for your remote repository>
然后,在您的gemfile中,取消注释最后一行下面的gem:
Windows does not have ...
从这个#gem zinfo [...]
要这样做:
gem zinfo [...]
到最后,运行
bundle install
更新您的lock.gemfile。
发布于 2020-06-16 14:02:55
我找不到文档,但很可能,WSL不支持fork()
函数。
您可以尝试使用spawn()
而不是fork()
。
https://stackoverflow.com/questions/62401042
复制相似问题