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

Run tests on Travis CI #224

Merged
merged 33 commits into from Aug 6, 2020
Merged

Run tests on Travis CI #224

merged 33 commits into from Aug 6, 2020

Conversation

abitrolly
Copy link
Collaborator

@abitrolly abitrolly commented Jul 29, 2020

Travis status from my fork https://travis-ci.com/github/abitrolly/cheat.sh/builds


They don't really work well.

image

@abitrolly
Copy link
Collaborator Author

@chubin now I am not sure what's going on. More output wouldn't hurt. Like the number of test and the command what is being executed.

https://travis-ci.com/github/abitrolly/cheat.sh/builds/177681447#L425

@abitrolly
Copy link
Collaborator Author

abitrolly commented Jul 29, 2020

It will take a lot of time for me to understand the shell runner. For example, what does this line do?

cat -n tests.txt | sed -n "$(echo "$*" | sed 's/ /p; /g;s/$/p/')"

@chubin
Copy link
Owner

chubin commented Jul 29, 2020

@abitrolly I believe you are doing it almost right, but it tries to use the standalone mode instead of the curl mode.

Let us take a look at the first test output:

CHEATSH_CACHE_TYPE=none python ../lib/standalone.py python/:list

Ok, it uses the standalone mode here, and we should curl instead.
If you set:

CHEATSH_TEST_STANDALONE=NO

What does this mean:

1,18d0
< 1line
< :learn
< :list
< Advanced
< Classes
< Comments
< Control_Flow
< Functions
< Modules
< Primitive_Datatypes_and_Operators
< Variables_and_Collections
< doc
< func
< hello
< lambda
< loops
< recursion
< rosetta/

?
This is a diff between what you've wanted and what you've got. Because it is running in a standalone mode
which delivers nothing, it is basically the whole expected page.

Regarding this:

cat -n tests.txt | sed -n "$(echo "$*" | sed 's/ /p; /g;s/$/p/')"`

The line looks so scary but it is pretty trivial:

 s{ }{p; }g;
 s{$}{p}

what yields:

1 2 3 => 1p; 2p; 3p;

which then is used as a short script for the outer sed printing the selected tests.
I had to document this better; here we just extract the tests that were passed as an arguments
to the test.sh.

So, to summarize, CHEATSH_TEST_STANDALONE=NO should be sufficient

@abitrolly
Copy link
Collaborator Author

@chubin what is the standalone mode? Does it mean ignoring the server?

@chubin
Copy link
Owner

chubin commented Jul 29, 2020

Yes, in the standalone mode you can use it without the server (say during a flight or in a submarine);
currently it does not support programming language queries in this mode though, only cheat sheet queries.
See #14 for some details

@abitrolly abitrolly mentioned this pull request Jul 30, 2020
@abitrolly
Copy link
Collaborator Author

I've discovered the Travis has numerous issues with ANSI escaping. Basically it is doing the same transformation of ANSI sequences as cheat.sh does to convert ANSI colored logs to HTML, and it looks like a not very maintainable hack https://github.com/travis-ci/travis-web/blob/master/app/utils/log.js#L236

@abitrolly
Copy link
Collaborator Author

abitrolly commented Jul 30, 2020

@@ -7,3 +7,9 @@ before_install:
- docker-compose up -d
- docker ps
- docker images

script:
- sleep 3

Choose a reason for hiding this comment

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

sleep is probably not a good way to know when the server is up. If you run it locally on a slower machine this can easily fail.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, cap. So any ideas how to fix that - https://travis-ci.com/github/abitrolly/cheat.sh/builds/177678164#L390? I checked - it is non-trivial

Choose a reason for hiding this comment

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

Retry after one second up to X if the exit code is 52 maybe?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

How exit code 52 is related?

Choose a reason for hiding this comment

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

The command "curl http://localhost:8002" exited with 52.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Then maybe better check until a port is accepting connections?

tests/run-tests.sh Show resolved Hide resolved
tests/run-tests.sh Show resolved Hide resolved
@abitrolly
Copy link
Collaborator Author

@SuperSandro2000 thanks for the comments on things not catched by shellcheck. It always good to have more pair of eyes. Any ideas why the tests fail?

Run Python 3 in unbuffered mode to see lines in `docker logs` as
soon as they appear. When Python 3 is not attached to a terminal,
it turns on the buffering, like when `docker` runs in a background.
Default `localhost:6379` doesn't work there. Trying to set
REDIS_HOST advertised in `run-tests.sh`
@abitrolly
Copy link
Collaborator Author

redis.exceptions.ConnectionError: Error 99 connecting to localhost:6379. Address not available.

2020-07-31T14:00:00Z {'REMOTE_ADDR': '172.18.0.1', 'REMOTE_PORT': '42306', 'HTTP_HOST': 'localhost:8002', (hidden keys: 20)} failed with ConnectionError

At last! Some progress.

@abitrolly
Copy link
Collaborator Author

REDIS_HOST env setting has no effect. Reading up on host cheat.sh config works https://github.com/chubin/cheat.sh/blob/f5d5fae71218e771e84b896600b2504c0d8814ec/lib/config.py

@abitrolly
Copy link
Collaborator Author

@chubin thsi is it. Travis runs test properly. The rest - updating and fixing the tests - could be done in subsequent PRs.

@abitrolly
Copy link
Collaborator Author

@@ -59,19 +71,24 @@ while read -r number test_line; do

if [ "$test_standalone" = YES ]; then
test_line="${test_line//cht.sh /}"
"${PYTHON}" ../lib/standalone.py "$test_line" > "$TMP" 2> /dev/null
[[ $show_details == YES ]] && echo "${PYTHON} ../lib/standalone.py $test_line"

Choose a reason for hiding this comment

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

You could convert this to a function which takes the string as an argument.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am not sure I am that bash proficient. Show an example?

Choose a reason for hiding this comment

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

log() {
  [[ $show_details == YES ]] && echo "$1" 
}

log("${PYTHON} ../lib/standalone.py $test_line")

@chubin chubin merged commit cd905f7 into chubin:master Aug 6, 2020
@chubin
Copy link
Owner

chubin commented Aug 6, 2020

@abitrolly

The PR is merged, thank you for the great work!

I've fixed the tests, they are almost all green now, except two tests, and they have, probably, the same problem.
Strange enough, this problem occurs only in the test environment, but not when running interactively.

That is how the correct expected behavior looks like:

$ curl -s http://localhost:8002/python/copy+file?QT
from shutil import copyfile

copyfile(src, dst)

Q means quiet mode, and T means no terminal,
but in the test environment the options seems to be ignored.

Could you please take a look at it?
If you will not find anything, then we will investigate deeper

Last build output:

https://travis-ci.org/github/chubin/cheat.sh/builds/715398758

@abitrolly
Copy link
Collaborator Author

@chubin I will try to quote them. Maybe there are some problems with shell expansion.

@abitrolly abitrolly deleted the run-tests branch August 6, 2020 07:43
@chubin
Copy link
Owner

chubin commented Aug 6, 2020

@abitrolly I don't think that this helps; try more debug output better instead

@abitrolly
Copy link
Collaborator Author

@chubin the part I don't understand is the usage of eval - could it be that eval does something to ? like expanding it as a shell pattern?

eval "curl -s $CHTSH_URL/$test_line" > "$TMP"

@abitrolly
Copy link
Collaborator Author

@chubin on my local instance accessing http://localhost:8002/python/copy+file complains that I am offline. Strange that it shows 200 status code. I haven't found a way to debug Flask yet. logging doesn't output anything on screen.

import logging
logging.error(url)
logging.error(response)

@chubin chubin mentioned this pull request Oct 12, 2020
@chubin
Copy link
Owner

chubin commented Oct 12, 2020

@abitrolly I am back online; sorry for the disappearance.
I will try to take a look at it and fix the problem

@abitrolly
Copy link
Collaborator Author

@chubin no pressure. I will be offline for at least two weeks too. )

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