Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace thread_safe with concurrent-ruby #2822

Conversation

junaruga
Copy link
Member

Because thread_safe is deprecated, as it was merged to concurrent-ruby.

https://github.com/ruby-concurrency/thread_safe
[DEPRECATED] Thread-safe collections for Ruby (merged with concurrent-ruby)

https://github.com/ruby-concurrency/concurrent-ruby
Collection classes that were originally part of the (deprecated) thread_safe gem:
...
Hash A thread-safe subclass of Ruby's standard Hash.
...

@junaruga
Copy link
Member Author

junaruga commented Jul 26, 2018

The Travis test was failed for only Ruby 1.8.
https://travis-ci.org/asciidoctor/asciidoctor/builds/408586518

Because concurrent-ruby latest version 1.0.5 requires Ruby >= 1.9.3.

To run concurrent-ruby on Ruby 1.8, we have to use the old version 0.5.0.
https://rubygems.org/gems/concurrent-ruby/versions/0.5.0
However the version 0.5.0 does not have Concurrent::Hash class. it might be implemented at different class.

How do you think to implement to fix it?
Do you like to implement to use thread_safe only if Ruby < 1.9.3 ?

@mojavelinux
Copy link
Member

Thanks for raising this issue.

Since we're not technically supporting Ruby 1.8.7 anymore, and this is just for tests, you can add an exception in the Gemfile.

Find:

if ruby_version < (Gem::Version.new '1.9.3')

and add:

gem 'thread_safe', '~> 0.3.0'

@mojavelinux
Copy link
Member

Can you also add an entry to the CHANGELOG.adoc when you update the PR? Please use the category "Build / Infrastructure". Thanks!

@mojavelinux mojavelinux added this to the v1.5.8 milestone Jul 27, 2018
require 'thread_safe'.to_s unless defined? ::ThreadSafe
new ::ThreadSafe::Cache.new
require 'concurrent'.to_s unless defined? ::Concurrent
new ::Concurrent::Hash.new
rescue ::LoadError
Copy link
Member Author

@junaruga junaruga Jul 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just for tests

thread_safe is not only for test. It is implemented.
Adding gem 'thread_safe', '~> 0.3.0' to Gemfile is meaningless, if we do not implement the conditional requiring thread_safe logic here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha! I see what you are saying. Let me think about it. We might be able to put stubs in place for Ruby 1.8.7 or we can just make this part of the 2.0.0 release.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I will wait you :)

@junaruga
Copy link
Member Author

junaruga commented Jul 27, 2018

Since we're not technically supporting Ruby 1.8.7 anymore, and this is just for tests, you can add an exception in the Gemfile.

Possible solution 1:

Add only concurrent-ruby to Gemfile, removing thread_safe from asciidoctor.gemspec.
As the test for concurrent-ruby is skipped on Ruby 1.8 when cucorrent-ruby is not installed, we can keep the Ruby 1.8 test case on Travis.

group :development do
...
  if ruby_version < (Gem::Version.new '1.9.3')
  ...
    else
..
      s.add_development_dependency 'concurrent-ruby', '~> 1.0.5'
    end

Possible solution 2:

Add both concurrent-ruby and thread_safe to Gemfile, removing thread_safe from asciidoctor.gemspec.

In this solution, we need implementation to use concurrent-ruby on Ruby >= 1.9.3, and thread_safe on only Ruby < 1.9.3.

Possible solution 3:

Just remove Ruby 1.8 test case from Travis, keeping s.add_development_dependency 'concurrent-ruby', '~> 1.0.5' in asciidoctor.gemspec.

@junaruga junaruga force-pushed the feature/replace_thread-safe-to-concurrent-ruby branch from 209d29c to 996608b Compare July 27, 2018 08:25
@junaruga
Copy link
Member Author

Can you also add an entry to the CHANGELOG.adoc when you update the PR? Please use the category "Build / Infrastructure". Thanks!

I can update the CHANGELOG.adoc. But is it the category "Build / Infrastructure"?
I replaced thread_safe used in the code at lib/asciidoctor/converter/factory.rb to concurrent in this PR.

@junaruga
Copy link
Member Author

By the way, though it's not related to this PR, seeing current Gemfile,

if ruby_version < (Gem::Version.new '1.9.3')

This kind of brackets style (Gem::Version.new 'X.Y.Z') is used in the file.
But maybe I think that Gem::Version.new('X.Y.Z') style is more popular like below code.

https://github.com/rubygems/rubygems/blob/v2.7.7/lib/rubygems/specification.rb#L2570
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then

Just I would share you the information :)

@mojavelinux
Copy link
Member

I'm very strongly in favor of lisp-style brackets when writing Ruby. I use it everywhere. I've documented this as part of the style for Asciidoctor projects here: https://github.com/asciidoctor/jekyll-asciidoc/blob/master/coding-style-guide.adoc. That will get moved into the documentation once we roll out 2.0.

@junaruga
Copy link
Member Author

Okay, it is great for this project to have a coding style guide.

@mojavelinux mojavelinux changed the title Replace thread_safe to concurrent-ruby. Replace thread_safe with concurrent-ruby Jul 31, 2018
@mojavelinux mojavelinux force-pushed the feature/replace_thread-safe-to-concurrent-ruby branch from 4cc9f30 to c3970de Compare July 31, 2018 06:29
@mojavelinux
Copy link
Member

I've proposed a revision which maps Concurrent::Hash to ThreadSafe::Cache in Ruby 1.8.7 so tests will pass. We really aren't worrying about Ruby 1.8.7 at this point, so as long as the CI job runs, it's fine.

@mojavelinux mojavelinux force-pushed the feature/replace_thread-safe-to-concurrent-ruby branch 3 times, most recently from d5f3133 to e6d2d7a Compare July 31, 2018 07:00
@mojavelinux
Copy link
Member

I recognize this solution is not pretty, but it's just temporary until Asciidoctor 2.0.0, when we'll be dropping support for all these old Ruby versions.

@junaruga
Copy link
Member Author

All right. I like the solution. The effort to support Ruby 1.8 until Asciidoctor 2.0.0.

By the way, you pushed your commit to my repository to add your commit in this PR.
I did not know that was possible. Did I give you the permission in the past time?
https://github.com/junaruga/asciidoctor/commits/feature/replace_thread-safe-to-concurrent-ruby

Anyway, thank you for the working.

Build / Infrastructure::

* replace thread_safe with concurrent-ruby (PR #2822) (*@junaruga*)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part should be changed? This PR is not only for Build / Infrastructure?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it changes the APIs used by this project, you're right. It's not just a dependency change. Therefore, it should now be under Improvements.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I moved it to Improvement.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@junaruga
Copy link
Member Author

Should I move my comment to another category in CHANGELOG.adoc?

@mojavelinux
Copy link
Member

By the way, you pushed your commit to my repository to add your commit in this PR.
I did not know that was possible. Did I give you the permission in the past time?

It's a rather recent feature of GitHub and it's the default setting when contributing to this project. This workflow makes it easier to collaborate on changes as you can communicate via code instead of words. It's also very helpful in cases when the contributor is not familiar with git (obviously not the case here).

@mojavelinux
Copy link
Member

mojavelinux commented Jul 31, 2018

The effort to support Ruby 1.8 until Asciidoctor 2.0.0.

It's not so much of an effort as just something that was never clearly defined. By moving to semantic versioning, we can do it (meaning drop it).

@junaruga
Copy link
Member Author

It's a rather recent feature of GitHub and it's the default setting when contributing to this project.

That's great feature for the collaboration. I did not know that.

you can communicate via code instead of words

I agree. This is really helpful.

@mojavelinux
Copy link
Member

Looks good! I'll get this merged tonight.

@ggrossetie
Copy link
Member

We might need to patch Asciidoctor.js and more specifically: https://github.com/asciidoctor/asciidoctor.js/blob/master/lib/asciidoctor/js/opal_ext/thread_safe.rb

I need to check but since we are now using ::Concurrent::Hash, we may need to define a "fake" class.

@@ -44,14 +44,14 @@ class << self
# Returns the default [Factory] singleton instance
def default initialize_singleton = true
return @__default__ || new unless initialize_singleton
# FIXME this assignment is not thread_safe, may need to use a ::Threadsafe helper here
# FIXME this assignment is not concurrent-ruby, may need to use a ::Threadsafe helper here
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we really want to say that the assignment is not "thread safe" right ?

And we may need to use a ::Concurrent (Ruby) helper.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right you are!

@mojavelinux
Copy link
Member

@Mogztter yes, we'll need something mapped in Opal. Something like:

module Concurrent
  class Hash < ::Hash
  end
end

That will replace the existing patch, though it doesn't hurt to keep both for now.

junaruga and others added 2 commits July 31, 2018 23:35
@mojavelinux mojavelinux force-pushed the feature/replace_thread-safe-to-concurrent-ruby branch from 5c1811d to 1685c24 Compare August 1, 2018 05:58
@mojavelinux
Copy link
Member

I made some updates. It should be sound now. I had forgotten about the case in factory.rb. (I am so looking forwarded to be rid of Ruby 1.8.7 from this code base).

@junaruga
Copy link
Member Author

junaruga commented Aug 1, 2018

@Mogztter thanks for the checking! @mojavelinux thanks for the updates! I checked it.

@mojavelinux mojavelinux merged commit f98cab8 into asciidoctor:master Aug 2, 2018
@mojavelinux
Copy link
Member

Thanks again! We can use this opportunity to test on AsciidoctorJ and Asciidoctor.js.

cc: @robertpanzer

@junaruga junaruga deleted the feature/replace_thread-safe-to-concurrent-ruby branch August 6, 2018 15:55
@ggrossetie
Copy link
Member

@mojavelinux We may have a missing test case because I didn't patch Asciidoctor.js and the build is still green...

@mojavelinux
Copy link
Member

Keep in mind this is only hit when registering a custom converter class or using the template converter. And Asciidoctor.js may already hit the fallback. But that's just a guess.

@ggrossetie
Copy link
Member

ggrossetie commented Oct 27, 2018

I removed Asciidoctor template.js from the test suite a while back I think that's why. I will add a test with a dummy custom converter.

EDIT: When I register a custom converter, the following warning is thrown asciidoctor: WARNING: gem 'concurrent-ruby' is not installed. This gem is recommended when registering custom converters. but otherwise it's working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants