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

DM-13608: Do not rely on locale when using diff #80

Merged
merged 2 commits into from Mar 1, 2018

Conversation

gcomoretto
Copy link
Collaborator

Not tested locally, need to be verified by the originator of the issue.
@RobertLuptonTheGood can you please verify if it works.

Copy link
Member

@jhoblitt jhoblitt left a comment

Choose a reason for hiding this comment

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

It isn't clear on the ticket exactly what the problem is or why setting LANG resolves it. I'm guessing that diff is responding to the locale rather than curl. Either way, it would be fanatic to add a unit test to https://github.com/lsst/lsst/blob/master/spec/unit/n8l/up2date_check_spec.rb that demonstrates the problem by setting LANG to a value that reproduces the failure.

@RobertLuptonTheGood
Copy link
Member

RobertLuptonTheGood commented Feb 22, 2018 via email

@jhoblitt
Copy link
Member

It is rather poor practice to use LANG=C in a unicode world and most linux distros have been defaulting to a utf-8 locale such as en_US.UTF-8 for the last decade or so.

Regardless, a trivial unit test will prevent a future regression.

@RobertLuptonTheGood
Copy link
Member

RobertLuptonTheGood commented Feb 22, 2018 via email

@timj
Copy link
Member

timj commented Feb 22, 2018

We spent a long time trying to write a test that would force diff to not use the word "differ" in the output but we failed. We even rebooted the mac into Italian and explicitly set LANG and LC_ALL and others in bash. Nothing worked. As pointed out by @PaulPrice on Jira, it would be much better if diff returned an exit status if two files differed rather than relying on the text string which may be locale-dependent.

@timj
Copy link
Member

timj commented Feb 22, 2018

@josh, it's not unicode that's the problem, it's that the message from diff can change depending on what language your computer is using.

@RobertLuptonTheGood
Copy link
Member

RobertLuptonTheGood commented Feb 22, 2018 via email

@jhoblitt
Copy link
Member

jhoblitt commented Feb 22, 2018

@timj I completely agree with @PaulPrice's suggestion but that doesn't mean that there should not be a unit test that demonstrates there is no breakage in various locales, which would be useful regardless of how the check is implemented. At present, I don't see any explanation on how to even reproduce the problem. The comment on unicode locales was just an FYI.

@timj
Copy link
Member

timj commented Feb 22, 2018

As I said, we tried to reproduce the problem but couldn't (and after an hour at it I decided it we were wasting our time -- Italian menus were interesting though). If you know what incantation is needed to trigger the issue on travis that would be great.

@timj
Copy link
Member

timj commented Feb 22, 2018

@jhoblitt why is the code checking the string value from that command? I just checked and cat blah | diff - blah2 does set $? to 1 if they differ and 0 if they are the same. Was there a reason you weren't checking $? instead?

@timj
Copy link
Member

timj commented Feb 26, 2018

@jhoblitt can you think of a reason why we can't check $? after running diff and just see if it is non-zero?

@timj
Copy link
Member

timj commented Mar 1, 2018

@gcomoretto the new version is failing the test suite because one of the tests does an exact match on the warning message contents and for some reason the test is no longer triggering the message:

https://travis-ci.org/lsst/lsst/jobs/347425710

@jhoblitt
Copy link
Member

jhoblitt commented Mar 1, 2018

@timj I'm not the author of that check, I merely preserved the original logic while trying to chop up the original script into a collection of smaller, hopefully testable, functions. I don't have any objection to testing for the exit status.

@timj
Copy link
Member

timj commented Mar 1, 2018

@jhoblitt can you help out @gcomoretto with the ruby test code that's failing? We are trying to work out whether the ruby test is looking explicitly for "differ" which no longer appears. Thanks.

@@ -501,15 +501,24 @@ n8l::up2date_check() {
set +e

local amidiff
amidiff=$($CURL "$CURL_OPTS" -L "$NEWINSTALL_URL" | diff --brief - "$0")
diff --brief "$0" <($CURL "$CURL_OPTS" -L "$NEWINSTALL_URL") > /dev/null
Copy link
Member

Choose a reason for hiding this comment

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

whitespace?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry, I corrected the missing tab. However I need some support for the ruby script.

Copy link
Member

Choose a reason for hiding this comment

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

Sure, I'll take a look.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you very much

@timj timj changed the title DM-13608: force LANG=C before curl command DM-13608: Do not rely on locale when using diff Mar 1, 2018
@jhoblitt
Copy link
Member

jhoblitt commented Mar 1, 2018

I've added a commit to the PR branch that updates the the rspec unit tests.

[DM-13608] ~/github/lsst $ bundle exec rspec --format doc -e n8l::up2date_check
Run options: include {:full_description=>/n8l::up2date_check/}

n8l::up2date_check
  script matches master
    prints nothing
  script out of sync with master
    prints a non-fatal warning
  unknown error comparing source against master
    prints a non-fatal warning

Finished in 0.38948 seconds (files took 0.10976 seconds to load)
3 examples, 0 failures

Assuming travis passes, this looks ready to merge but the commits probably should be squashed and the original commit message updated.

@jhoblitt
Copy link
Member

jhoblitt commented Mar 1, 2018

I rebased the PR on current master after the merge of #81 .

gcomoretto and others added 2 commits March 1, 2018 11:35
String output change with locale, using the exit status is more robust
and easy to unit test.
@gcomoretto
Copy link
Collaborator Author

With the help of @timj I squash my commits into one in the rebased branch. @jhoblitt can approve the pull request, if all problems have been sorted out?

Copy link
Member

@jhoblitt jhoblitt left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for sticking with it.

@gcomoretto gcomoretto merged commit ee511c3 into master Mar 1, 2018
@ktlim ktlim deleted the tickets/DM-13608 branch August 25, 2018 06:15
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

4 participants