diff --git a/ext/iou/op_ctx.c b/ext/iou/op_ctx.c index 8e30646..58b18b8 100644 --- a/ext/iou/op_ctx.c +++ b/ext/iou/op_ctx.c @@ -41,7 +41,6 @@ VALUE OpCtx_initialize(VALUE self, VALUE spec, VALUE proc) { VALUE OpCtx_spec(VALUE self) { OpCtx_t *osd = RTYPEDDATA_DATA(self); - return osd->spec; } diff --git a/test/test_iou.rb b/test/test_iou.rb index 02d1582..1a85e30 100644 --- a/test/test_iou.rb +++ b/test/test_iou.rb @@ -799,3 +799,36 @@ def test_prep_read_multishot_utf8 assert_nil ring.pending_ops[id] end end + +class OpCtxTest < IOURingBaseTest + def test_ctx_spec + id = ring.emit(foo: :bar) + assert_equal({ foo: :bar, id: 1, op: :emit }, ring.pending_ops[id].spec) + end + + def test_ctx_type + id = ring.emit(v: 1) + assert_equal 1, id + assert_equal :emit, ring.pending_ops[id].spec[:op] + + id = ring.prep_timeout(interval: 1) + assert_equal 2, id + assert_equal :timeout, ring.pending_ops[id].spec[:op] + + id = ring.prep_read(fd: STDIN.fileno, buffer: +'', len: 42) + assert_equal 3, id + assert_equal :read, ring.pending_ops[id].spec[:op] + + id = ring.prep_write(fd: STDOUT.fileno, buffer: '') + assert_equal 4, id + assert_equal :write, ring.pending_ops[id].spec[:op] + + id = ring.prep_accept(fd: STDIN.fileno) + assert_equal 5, id + assert_equal :accept, ring.pending_ops[id].spec[:op] + + id = ring.prep_close(fd: STDIN.fileno) + assert_equal 6, id + assert_equal :close, ring.pending_ops[id].spec[:op] + end +end