[前][次][番号順一覧][スレッド一覧]

ruby-changes:52152

From: normal <ko1@a...>
Date: Wed, 15 Aug 2018 02:07:45 +0900 (JST)
Subject: [ruby-changes:52152] normal:r64359 (trunk): spec/ruby/optional/capi/io_spec.rb: fix fragile spec from unpredictable errno

normal	2018-08-15 02:07:36 +0900 (Wed, 15 Aug 2018)

  New Revision: 64359

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64359

  Log:
    spec/ruby/optional/capi/io_spec.rb: fix fragile spec from unpredictable errno
    
    rb_io_wait_readable and rb_io_wait_writable depend on the TSD
    errno value.  Due to the recent changes in r64352-r64353 to
    restructure GVL, errno could be set to EAGAIN from the signal
    self-pipe and cause the rb_io_wait_readable spec to block
    unexpectedly.  This should fix rubyspec timeouts on Solaris:
    
      http://rubyci.s3.amazonaws.com/unstable11s/ruby-trunk/log/20180814T042506Z.fail.html.gz
    
    * spec/ruby/optional/capi/ext/io_spec.c: add errno= setter method
    * spec/ruby/optional/capi/io_spec.rb: set errno to appropriate values for tests

  Modified files:
    trunk/spec/ruby/optional/capi/ext/io_spec.c
    trunk/spec/ruby/optional/capi/io_spec.rb
Index: spec/ruby/optional/capi/io_spec.rb
===================================================================
--- spec/ruby/optional/capi/io_spec.rb	(revision 64358)
+++ spec/ruby/optional/capi/io_spec.rb	(revision 64359)
@@ -236,6 +236,7 @@ describe "C-API IO function" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/optional/capi/io_spec.rb#L236
 
   describe "rb_io_wait_writable" do
     it "returns false if there is no error condition" do
+      @o.errno = 0
       @o.rb_io_wait_writable(@w_io).should be_false
     end
 
@@ -254,6 +255,7 @@ describe "C-API IO function" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/optional/capi/io_spec.rb#L255
   platform_is_not :windows do
     describe "rb_io_wait_readable" do
       it "returns false if there is no error condition" do
+        @o.errno = 0
         @o.rb_io_wait_readable(@r_io, false).should be_false
       end
 
@@ -271,6 +273,7 @@ describe "C-API IO function" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/optional/capi/io_spec.rb#L273
           @w_io.write "rb_io_wait_readable"
         end
 
+        @o.errno = Errno::EAGAIN.new.errno
         @o.rb_io_wait_readable(@r_io, true).should be_true
         @o.instance_variable_get(:@read_data).should == "rb_io_wait_re"
 
Index: spec/ruby/optional/capi/ext/io_spec.c
===================================================================
--- spec/ruby/optional/capi/ext/io_spec.c	(revision 64358)
+++ spec/ruby/optional/capi/ext/io_spec.c	(revision 64359)
@@ -218,6 +218,17 @@ VALUE io_spec_rb_io_close(VALUE self, VA https://github.com/ruby/ruby/blob/trunk/spec/ruby/optional/capi/ext/io_spec.c#L218
 }
 #endif
 
+/*
+ * this is needed to ensure rb_io_wait_*able functions behave
+ * predictably because errno may be set to unexpected values
+ * otherwise.
+ */
+static VALUE io_spec_errno_set(VALUE self, VALUE val) {
+  int e = NUM2INT(val);
+  errno = e;
+  return val;
+}
+
 void Init_io_spec(void) {
   VALUE cls = rb_define_class("CApiIOSpecs", rb_cObject);
 
@@ -296,6 +307,8 @@ void Init_io_spec(void) { https://github.com/ruby/ruby/blob/trunk/spec/ruby/optional/capi/ext/io_spec.c#L307
 #ifdef HAVE_RB_CLOEXEC_OPEN
   rb_define_method(cls, "rb_cloexec_open", io_spec_rb_cloexec_open, 3);
 #endif
+
+  rb_define_method(cls, "errno=", io_spec_errno_set, 1);
 }
 
 #ifdef __cplusplus

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]