Skip to content

Add unit tests for XMLRPC::CGIServer #60

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

Merged
merged 4 commits into from
May 16, 2025
Merged

Add unit tests for XMLRPC::CGIServer #60

merged 4 commits into from
May 16, 2025

Conversation

herwinw
Copy link
Member

@herwinw herwinw commented Apr 29, 2025

The implementation is mostly a copy-paste from the webrick server test, including the code style.
Because this needs a CGI server, it still has a dependency on webrick to run that server. This setup is a bit slow, on my system the overall execution time of the tests jumps from 1 second to 7 seconds.

@herwinw herwinw force-pushed the cgi branch 2 times, most recently from 0de88c5 to fb9cc7f Compare April 29, 2025 14:06
@herwinw
Copy link
Member Author

herwinw commented Apr 29, 2025

I've disabled these new tests on Windows platforms, the CGI structure needs an executable file and the usual #!/usr/bin/env ruby and chmod +x does not work on Windows. This can probably be fixed, but I have no idea how.

end

def test_client_server
omit("The CGI file does not work on Windows") if RUBY_PLATFORM =~ /(mswin|mingw)/
Copy link
Member

Choose a reason for hiding this comment

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

We can use Gem.win_platform?:

Suggested change
omit("The CGI file does not work on Windows") if RUBY_PLATFORM =~ /(mswin|mingw)/
omit("The CGI file does not work on Windows") if Gem.win_platform?

tempfile.close
File.chmod(0755, tempfile.path)

[false].each do |use_ssl|
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
[false].each do |use_ssl|
use_ssl = false


[false].each do |use_ssl|
option = setup_http_server_option(use_ssl)
with_server(option, WEBrick::HTTPServlet::CGIHandler, tempfile.path) {|addr|
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
with_server(option, WEBrick::HTTPServlet::CGIHandler, tempfile.path) {|addr|
with_server(option, WEBrick::HTTPServlet::CGIHandler, tempfile.path) do |addr|


def cgi_bin_script
<<~RUBY
#!/usr/bin/env ruby
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#!/usr/bin/env ruby
#!#{Gem.ruby}

end

s.set_default_handler do |name, *args|
raise XMLRPC::FaultException.new(-99, "Method #{name} missing" +
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
raise XMLRPC::FaultException.new(-99, "Method #{name} missing" +
raise XMLRPC::FaultException.new(-99, "Method \#{name} missing" +


s = XMLRPC::CGIServer.new

s.add_handler("test.add") do |a,b|
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
s.add_handler("test.add") do |a,b|
s.add_handler("test.add") do |a, b|

a + b
end

s.add_handler("test.div") do |a,b|
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
s.add_handler("test.div") do |a,b|
s.add_handler("test.div") do |a, b|

assert_equal param, 2

# introspection
assert_equal ["test.add", "test.div", "system.listMethods", "system.methodSignature", "system.methodHelp"], @s.call("system.listMethods")
Copy link
Member

Choose a reason for hiding this comment

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

Could you avoid omitting parenthesis for assertions?
See also: https://bugs.ruby-lang.org/issues/20922

Could you align long expected and actual for readability?

Suggested change
assert_equal ["test.add", "test.div", "system.listMethods", "system.methodSignature", "system.methodHelp"], @s.call("system.listMethods")
assert_equal(["test.add", "test.div", "system.listMethods", "system.methodSignature", "system.methodHelp"],
@s.call("system.listMethods"))

herwinw added 3 commits May 15, 2025 14:53
These remarks originate from the review of the tests of the CGI server,
but since most of that code was copied from this file, clean this up
here as well.
If we ever want to use shared logic for these files, it's preferable to
keep the differences to a minimum.
The do not work out of the box, I'm sure this can be fixed but I have no idea
how to do that.
@herwinw
Copy link
Member Author

herwinw commented May 15, 2025

I think I've fixed all review comments now. Since the code started out as a copy-paste of the Webrick tests, they layout/paren fixes have been fixed in that file as well. This keeps the differences between these two files to a minimum.

@herwinw
Copy link
Member Author

herwinw commented May 15, 2025

The issues with macos head/ubuntu head are related to the removal of the CGI gem from Ruby 3.5. This looks to be fixed upstream in rack/rack#2327, but is not yet released. These should not occur when running the CI on master as well.
And windows-mingw appears to be the same issue (https://github.com/ruby/xmlrpc/actions/runs/15045607126/job/42287265042), I was afraid the Gem.win_platform? change broke things.

@kou kou merged commit 690dd66 into ruby:master May 16, 2025
24 of 27 checks passed
@kou
Copy link
Member

kou commented May 16, 2025

Let's work on CGI gem + Ruby 3.5 in a separated PR.

@herwinw herwinw deleted the cgi branch May 17, 2025 07:29
@herwinw
Copy link
Member Author

herwinw commented May 17, 2025

Let's work on CGI gem + Ruby 3.5 in a separated PR.

That should be fixed with the next release of Rack. If you use gem "rack", github: 'rack/rack' in the Gemfile, it works with Ruby 3.5-dev again. With the information of https://rubygems.org/gems/rack/versions, it looks like they're doing roughly 1 release per month, so it will probably be fixed automatically within the next few weeks.

@kou
Copy link
Member

kou commented May 19, 2025

OK. Rack 3.1.15 was related on 2025-05-18 and CI works again.

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.

2 participants