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

Expansion of unit tests for utils/utils.go #818

Closed
wants to merge 1 commit into from

Conversation

owenwaller
Copy link
Contributor

This commit expands the test coverage for the utils/utils.go module.

The utils module uses the 'github.com/spf13/jwalterweatherman' (aka jww)
package for logging. The tests take the approach of examining the log
file that is produced by this module to verify correct behaviour. This
avoids refactoring the utils module.

The log file messages written by the jww module are of the form:
: yyyy/mm/dd <string|error message>

The checkLogFile function checks each of these parts in turn except for
the date string, which is currently ignored. The final part of the log
file format can either be a single error message, or a series of
strings followed by an error message. Both the error message and the
series of strings can be empty strings.

The log file is checked using a combination of the regex package,
along with the bufio scanner type. Each test logs to its own temporary
log file. This is achieved with standard test setup and teardown
functions.

One consequence of these tests is that StopOnErr has been refactored
into call a new unexported function doStopOnErr which contains the bulk
of the original logic. This allows the same testing approach to be used
with StopOnErr as with CheckErr and cutUsageMessage, rather than look at
the exit status code of the test itself.

An unfortunate side effect of this is that the author of the tests must
now know if a log file is expected or not. If doStopOnErr determines
that an empty error message would be written to the log file then
nothing is written. In the context of the tests this means that the log
file created by the test would have no contents. Consequently there
would be nothing for the test to examine. This situation is indicated by
the boolean flag logFileExoected in the testData struct, and processed
by the logFileIsExpectedAndValid function.

Although not ideal this was deemed a reasonable compromise.

This commit expands the test coverage for the utils/utils.go module.

The utils module uses the 'github.com/spf13/jwalterweatherman' (aka jww)
package for logging. The tests take the approach of examining the log
file that is produced by this module to verify correct behaviour. This
avoids refactoring the utils module.

The log file messages written by the jww module are of the form:
<log level>: yyyy/mm/dd <string|error message>

The checkLogFile function checks each of these parts in turn except for
the date string, which is currently ignored. The final part of the log
file format can either be a single error message, or a series of
strings followed by an error message. Both the error message and the
series of strings can be empty strings.

The log file is checked using a combination of the regex package,
along with the bufio scanner type. Each test logs to its own temporary
log file. This is achieved with standard test setup and teardown
functions.

One consequence of these tests is that StopOnErr has been refactored
into call a new unexported function doStopOnErr which contains the bulk
of the original logic. This allows the same testing approach to be used
with StopOnErr as with CheckErr and cutUsageMessage, rather than look at
the exit status code of the test itself.

An unfortunate side effect of this is that the author of the tests must
now know if a log file is expected or not. If doStopOnErr determines
that an empty error message would be written to the log file then
nothing is written. In the context of the tests this means that the log
file created by the test would have no contents. Consequently there
would be nothing for the test to examine. This situation is indicated by
the boolean flag logFileExoected in the testData struct, and processed
by the logFileIsExpectedAndValid function.

Although not ideal this was deemed a reasonable compromise.
@bep
Copy link
Member

bep commented Jan 23, 2015

Could you do a push -f to trigger new builds?

@anthonyfok
Copy link
Member

Sorry all, I merged this prematurely. Should have waited @owenwaller to git push -f it to trigger a test build, as this is failing on Windows, and I will need to revert this PR for now:

--- FAIL: TestCheckErr (0.01 seconds)
    utils_test.go:177: Error: Could not remove file "f". Error: remove C:\Users\appveyor\AppData\Local\Temp\utils_test_773934895: The process cannot access the file because it is being used by another process.
    utils_test.go:177: Error: Could not remove file "f". Error: remove C:\Users\appveyor\AppData\Local\Temp\utils_test_063973136: The process cannot access the file because it is being used by another process.
    utils_test.go:177: Error: Could not remove file "f". Error: remove C:\Users\appveyor\AppData\Local\Temp\utils_test_960236341: The process cannot access the file because it is being used by another process.
    utils_test.go:177: Error: Could not remove file "f". Error: remove C:\Users\appveyor\AppData\Local\Temp\utils_test_764374446: The process cannot access the file because it is being used by another process.
    utils_test.go:177: Error: Could not remove file "f". Error: remove C:\Users\appveyor\AppData\Local\Temp\utils_test_580651211: The process cannot access the file because it is being used by another process.
=== RUN TestDoStopOnErr
Logging to C:\Users\appveyor\AppData\Local\Temp\utils_test_504241858
Logging to C:\Users\appveyor\AppData\Local\Temp\utils_test_057641273
Logging to C:\Users\appveyor\AppData\Local\Temp\utils_test_913919812
Logging to C:\Users\appveyor\AppData\Local\Temp\utils_test_001469907
Logging to C:\Users\appveyor\AppData\Local\Temp\utils_test_622529814
Logging to C:\Users\appveyor\AppData\Local\Temp\utils_test_131851645
Logging to C:\Users\appveyor\AppData\Local\Temp\utils_test_839439544
Logging to C:\Users\appveyor\AppData\Local\Temp\utils_test_964376247
Logging to C:\Users\appveyor\AppData\Local\Temp\utils_test_747965610
--- FAIL: TestDoStopOnErr (0.01 seconds)
    utils_test.go:177: Error: Could not remove file "f". Error: remove C:\Users\appveyor\AppData\Local\Temp\utils_test_747965610: The process cannot access the file because it is being used by another process.
    utils_test.go:177: Error: Could not remove file "f". Error: remove C:\Users\appveyor\AppData\Local\Temp\utils_test_964376247: The process cannot access the file because it is being used by another process.
    utils_test.go:177: Error: Could not remove file "f". Error: remove C:\Users\appveyor\AppData\Local\Temp\utils_test_839439544: The process cannot access the file because it is being used by another process.
    utils_test.go:177: Error: Could not remove file "f". Error: remove C:\Users\appveyor\AppData\Local\Temp\utils_test_131851645: The process cannot access the file because it is being used by another process.
    utils_test.go:177: Error: Could not remove file "f". Error: remove C:\Users\appveyor\AppData\Local\Temp\utils_test_622529814: The process cannot access the file because it is being used by another process.
    utils_test.go:177: Error: Could not remove file "f". Error: remove C:\Users\appveyor\AppData\Local\Temp\utils_test_001469907: The process cannot access the file because it is being used by another process.
    utils_test.go:177: Error: Could not remove file "f". Error: remove C:\Users\appveyor\AppData\Local\Temp\utils_test_913919812: The process cannot access the file because it is being used by another process.
    utils_test.go:177: Error: Could not remove file "f". Error: remove C:\Users\appveyor\AppData\Local\Temp\utils_test_057641273: The process cannot access the file because it is being used by another process.
    utils_test.go:177: Error: Could not remove file "f". Error: remove C:\Users\appveyor\AppData\Local\Temp\utils_test_504241858: The process cannot access the file because it is being used by another process.
FAIL
coverage: 84.2% of statements
FAIL    github.com/spf13/hugo/utils 0.160s

Hi @owenwaller, still here? Could you please look into it? Thanks!

@anthonyfok anthonyfok modified the milestones: future, v0.13 Feb 17, 2015
anthonyfok added a commit that referenced this pull request Feb 17, 2015
Rationale: Test failing on Windows with errors like this:

    utils_test.go:177: Error: Could not remove file "f".
    Error: remove C:\Users\appveyor\AppData\Local\Temp\utils_test_747965610:
    The process cannot access the file because it is being used by another
    process.

This reverts commit 6b28e38.

Sorry for my premature merge of Pull Request #818.
@owenwaller
Copy link
Contributor Author

@anthonyfok @bep

Hi Guys, Sorry I've just seen this. I've been extremely busy with other things for the last month.

So, I've had a quick look and fairly obviously I don't see this failure on Linux. So my first question is do either of you two have a Windows box we can try something on, as I don't?

But... the file "f" is the temporary file that is passed to the jww logger instance so we can later parse it to check the results. It's created with:

    const logfilename = "utils_test_"
    f, err := ioutil.TempFile(os.TempDir(), logfilename)

That's lines 163, 164 in utils/utils_test.go

The error is suggesting that the file is locked. As you can see from the ci log the file names are all unique - the jww package (helpfully in this case) spits out the filename, but the only process that should ever touch this file is the one that created it which is the test itself.

But, even if every TestXxxx in the set was run in its own process, the file that is used for logging is local to each TestXxxx function. So again is should be ok as only one process is accessing the file.

So I'm kinda stumped at this point. Can someone give me some details of this appveyor thing and what their set up might be? I can see that it's only the appveyor build that falls over with this.

My one short in the dark would be this.... If you look at the filename, it's all rooted on the same path and that path doesn't look to be very unique - i.e .it doesn't appear to have anything like a build number or string that relates it uniquely to hugo. So assuming a large enough scale and a fast enough rate, I guess it's possible for another process/ci run in the appveyor environment to create a file with the same name at the same path. I admit that seeing this it does make my prefix of "utils_test_" look less than ideal. So that can certainly be improved. But as I said this is a shot in the dark at this point.

Owen

@owenwaller
Copy link
Contributor Author

@anthonyfok @bep @spf13

Folks in order to take a look at this, I've set-up an account on AppVeyor and am trying building the current master branch via AppVeyor. So my last commit is: a389268.

Having not used AppVeyor before this seems the simplest test I could do, since the master branch should be golden...

But it's not building - See:https://ci.appveyor.com/project/owenwaller/hugo/build/1.0.23 for my latest attempt.

Also AppVoyer is using go 1.3 wndows/amd64 as you can see from the build output, though I am not sure this is any effect. But I'm using go 1.4.1 locally on Linux and I don't have a problem building this branch.

So can anyone spot anything that I might have missed?

@spf13 Steve can you send me a copy of you AppVeyor settings so I can be sure that I have the same settings as a the build node you are using? Or create an Appveyor.yml and share that.

But at the minute until I get the current master branch to build I'm a bit stuck :(. My plan is then to rebase my original pull request on the latest master and see if I can reproduce the issue.

(I see similar behaviour is I try to build my original utils-test-code that contained the original pull request. So this looks like a Windows/AppVeyor only thing at the minute)

Any help at this stage would be much appreciated.

Owen

@spf13
Copy link
Contributor

spf13 commented Feb 19, 2015

I'm looking into this now. I'll try to share with you what I have. 

Best,
Steve

-- 
Steve Francia
http://stevefrancia.com
http://spf13.com
http://twitter.com/spf13

On February 19, 2015 at 8:22:14 AM, Owen Waller (notifications@github.com) wrote:

@anthonyfok @bep @spf13

Folks in order to take a look at this, I've set-up an account on AppVeyor and am trying building the current master branch via AppVeyor. So my last commit is: a389268.

Having not used AppVeyor before this seems the simplest test I could do, since the master branch should be golden...

But it's not building - See:https://ci.appveyor.com/project/owenwaller/hugo/build/1.0.23 for my latest attempt.

Also AppVoyer is using go 1.3 wndows/amd64 as you can see from the build output, though I am not sure this is any effect. But I'm using go 1.4.1 locally on Linux and I don't have a problem building this branch.

So can anyone spot anything that I might have missed?

@spf13 Steve can you send me a copy of you AppVeyor settings so I can be sure that I have the same settings as a the build node you are using? Or create an Appveyor.yml and share that.

But at the minute until I get the current master branch to build I'm a bit stuck :(. My plan is then to rebase my original pull request on the latest master and see if I can reproduce the issue.

(I see similar behaviour is I try to build my original utils-test-code that contained the original pull request. So this looks like a Windows/AppVeyor only thing at the minute)

Any help at this stage would be much appreciated.

Owen


Reply to this email directly or view it on GitHub.

@spf13
Copy link
Contributor

spf13 commented Feb 19, 2015

Ok, @owenwaller here's the YAML file. It's quite short.

version: 1.0.{build}
clone_folder: C:\GOPATH\src\github.com\spf13\hugo
environment:
  GOPATH: C:\GOPATH
build_script:
- go get -v -d -t ./...
test_script:
- go test -v -cover ./...

@mohae
Copy link
Contributor

mohae commented Feb 19, 2015

There may still be problems if appveyor is still using 1.3 since some of the path issues are fixed by bug fixes that were part of 1.4.

I'll try to take a look at this on Windows today.

@bep
Copy link
Member

bep commented Feb 19, 2015

None of the path issues I fixed was fixed by 1.4 stuff.

@owenwaller if you just push to your utils-test-cod branch, it will trigger a build with Hugo's build setup.

@owenwaller
Copy link
Contributor Author

Joel,

Assuming this is the case - and I half suspect you may be correct - then
I see to approaches.

A) ask Appveyor to see if they will officially add support for go 1.4.X
and commit to keeping it up to date, so that's the go v 1.4.X series and
then go 1.5 and onwards.
or
b) Try this as a workaround:
http://help.appveyor.com/discussions/problems/1215-go-14-support
It seems we can install go v1.4 locally - I've not tried this myself
yet. The issue I have with this is that it means we are going to be
dragging a full go install tarball over the net for every build. Which
seems just a little excessive, and that can't be good for appveyor in
terms of bandwidth or costs. And obviously for us it slows the build
down considerably

Owen

On Thu, 2015-02-19 at 08:34 -0800, Joel Scoble wrote:

There may still be problems if appveyor is still using 1.3 since some
of the path issues are fixed by bug fixes that were part of 1.4.

I'll try to take a look at this on Windows today.


Reply to this email directly or view it on GitHub.

Dr. Owen Waller
Head of Development
Kulawe Limited
Forsyth House
Cormac Square
Belfast
Northern Ireland
BT2 8LA

+44 (0)757 882 9933
info@kulawe.com
www.kulawe.com

Company Number: NI604010
VAT Number : GB 122 6319 42

@owenwaller
Copy link
Contributor Author

@spf13 - ta for the yml file. I've attached the YML file I'm using - the
only change is that it's pulling from my repo and the default branch (as
specified in the project settings) is my appveyor branch - as you can
see form the log.

OK I've just tried it again and no dice. Results here:
https://ci.appveyor.com/project/owenwaller/hugo/build/1.0.24

Now we are missing packages... and at least "github.com/kr/pty" should
be linux only, as that's the Linux Pseudo TY emulation layer. It's being
dragging in as part of the test code for something else though. I'm
trying to track down just what at the minute.

@bep - ok pushing to my repo public auto triggered the build on my
apveyor account. So that's fine. If you want me to push to the upstream
spf13.hugo repo then I think I have permissions for that, but I'd rather
not push anything to the master branch till we get this sorted out. I'm
happy to push what I currently have to a new branch in Steve's root
repo, if that will also trigger a build based on his settings.

Owen

On Thu, 2015-02-19 at 09:51 -0800, Bjørn Erik Pedersen wrote:

None of the path issues I fixed was fixed by 1.4 stuff.

@owenwaller if you just push to your utils-test-cod branch, it will
trigger a build with Hugo's build setup.


Reply to this email directly or view it on GitHub.

Dr. Owen Waller
Head of Development
Kulawe Limited
Forsyth House
Cormac Square
Belfast
Northern Ireland
BT2 8LA

+44 (0)757 882 9933
info@kulawe.com
www.kulawe.com

Company Number: NI604010
VAT Number : GB 122 6319 42

@bep
Copy link
Member

bep commented Feb 19, 2015

The build above fails for an old reason that is fixed:

page_permalink_test.go:68: Test 0: Expected abs url: /x/y/z/boofar/, got: x/y/z/boofar/

@owenwaller - as I asked you a couple time already, could you just trigger a new build by doing a push -f?

@mohae
Copy link
Contributor

mohae commented Feb 19, 2015

@bep thanks for the info. I had been thinking about #699, problems with FindCWD() on Windows. and things affected by Go issue 8090

@owenwaller I guess, for now, using the suggested method is the way that we need to do testing if 1.4 is actually needed for test passing. @bep's comment make me wonder if my assumption that it was is true.

@bep
Copy link
Member

bep commented Feb 19, 2015

@mohae @owenwaller the failure in the current failure above was caused by #878 - there may be other issues, but do a push first.

@owenwaller
Copy link
Contributor Author

@bep.

Has a fix for #878 been merged into the hugo master line as of about
09:00 this morning UK time?
Because, I'm just trying to build hugo's master branch at this point. My
pull request #818 shouldn't be in this code (yet) @anthonyfok tried and
reverted it.

So, I'm happy to do a push -f(*) but to the upstream repo (spf13/hugo?)
and do you want this in a new branch? As I've said I'd rather not stuff
up the master branch any more than it currently appears to be. And
besides my current appveyor branch would be identical to the
spf13/hugo/master branch in any case - bar my addition of the
appveyor.yml file

I'm am quite happy to add a dummy commit onto the spf13/hugo.master
branch if that's all it takes to trigger an appveyor build on spf13's
repo, if that's what is required here.

(*)Not that the -f switch should be necessary. My push should not be
overwriting anything and everyone's local branches should be an ancestor
of remote master branch in any case.

Owen

On Thu, 2015-02-19 at 10:18 -0800, Bjørn Erik Pedersen wrote:

@mohae @owenwaller the failure in the current failure above was caused
by #878 - there may be other issues, but do a push first.


Reply to this email directly or view it on GitHub.

Dr. Owen Waller
Head of Development
Kulawe Limited
Forsyth House
Cormac Square
Belfast
Northern Ireland
BT2 8LA

+44 (0)757 882 9933
info@kulawe.com
www.kulawe.com

Company Number: NI604010
VAT Number : GB 122 6319 42

@bep
Copy link
Member

bep commented Feb 19, 2015

@owenwaller do a rebase against master, then push -f

@owenwaller
Copy link
Contributor Author

@bep

That won't make any difference in this case. My appveyor branch that is being build via Appveyor was a clean cloned copy of spf13's repo that I took this morning. I've just done a git fetch against the upstream and nothing has changed.

Alternatively, if you just take a branch the upstream master branch, and set up an appveyor account, you should see what I an currently seeing. In fact it would help if you can conform that assumption :)

@spf13
As an aside, exactly which work flow are we using on hugo? @bep is suggesting that it's a rebase as opposed to a merge based workflow? Is that correct,I though we where on merge based...

@bep
Copy link
Member

bep commented Feb 19, 2015

@owenwaller git rebase master + git push -f. I'm asking you to do something that takes 20 keystrokes. Do it, or don't.

@spf13
Copy link
Contributor

spf13 commented Feb 19, 2015 via email

@mohae
Copy link
Contributor

mohae commented Feb 19, 2015

I added a request for AppVeyor to upgrade to 1.4 on http://help.appveyor.com/discussions/problems/1215-go-14-support. They said they would update this week.

But that won't address the failures within these tests on Windows.

First I added a sleep to teardown() before removing the file, which didn't work.

I then:

  • Created a tempDir using init() and placed all the testing logfiles in there.
  • Changed teardown() do an os.RemoveAll() on the temp directory.
  • Changed setup() to return the *os.File in addition to the filename.
  • Added a f.Close() to the returned file handle in the testing code.
  • Added jww.DiscardLogging() before calling `f.Close().
  • Created a main test function which ran the tests and after all tests were run called teardown().

These changes, which were made incrementally, also failed due to the files still being in use.

The root of the problem is that jww never closes any files. It relies on the program exiting to close the filies. It doesn't appear that these tests will pass on Windows until there is a way of telling jww to close its log files.

For jww, I think that calling DiscardLogging() might be an appropriate place to close files, or any other function which allows for the Handle to be changed.

Regardless, I don't think there is a way for these tests, as currently written, to pass until there are changes on the jww side.

@spf13
Copy link
Contributor

spf13 commented Feb 19, 2015

We can add ways to close things on jww. Do you want to send a PR?

@mohae
Copy link
Contributor

mohae commented Feb 19, 2015

I've made some local changes to support closing things on jww, but I'm still getting inconsistent and strange results when running the tests on Windows. I'm trying to figure out the cause/if my assumption about the root cause of the failure is correct.

@owenwaller
Copy link
Contributor Author

@mohae Good man. I had a very quick glance at jww yesterday when I
first became aware that my new tests failed on Windows. I did wonder
about how the log file was closed but I had thought my call to
os.Remove() in my teardown() method would have been sufficient. But
having just looked at the src for os.Remove that's a nope.

So I've been relying on the program exit behaviour on Linux to close the
file implicitly. Which is why I've not seen this problem. So the code is
defiantly missing a call to f.Close somewhere. So that’s my goof.

So I agree with you, the tests as written won't work. So I need to fix
these.

Now the question is where does the Close() go? My current feeling
would be in jww somewhere as that keeps the "just use it" spirit of
jww.

What does everyone else think?

Also @mohae, I'm assuming you are running this on Windows? ;) If this
the case can you do me a favour. Take a fresh clone of the master repo
and see if the current master branch builds. I'm also trying to work out
why Appveyor is apparently failing at the build stage - see my latest
Appveyor build result above. As that should (in theory work). At the
minute I can't work out if the build failure is a Windows or an Appveyor
thing.

Owen

On Thu, 2015-02-19 at 13:32 -0800, Joel Scoble wrote:

I added a request for AppVeyor to upgrade to 1.4 on
http://help.appveyor.com/discussions/problems/1215-go-14-support. They
said they would update this week.

But that won't address the failures within these tests on Windows.

First I added a sleep to teardown() before removing the file, which
didn't work.

I then:

  * Created a tempDir using init() and placed all the testing
    logfiles in there.
  * Changed teardown() do an os.RemoveAll() on the temp directory.
  * Changed setup() to return the *os.File in addition to the
    filename.
  * Added a f.Close() to the returned file handle in the testing
    code.
  * Added jww.DiscardLogging() before calling `f.Close().
  * Created a main test function which ran the tests and after all
    tests were run called teardown().

These changes, which were made incrementally, also failed due to the
files still being in use.

The root of the problem is that jww never closes any files. It relies
on the program exiting to close the filies. It doesn't appear that
these tests will pass on Windows until there is a way of telling jww
to close its log files.

For jww, I think that calling DiscardLogging() might be an appropriate
place to close files, or any other function which allows for the
Handle to be changed.

Regardless, I don't think there is a way for these tests, as currently
written, to pass until there are changes on the jww side.


Reply to this email directly or view it on GitHub.

Dr. Owen Waller
Head of Development
Kulawe Limited
Forsyth House
Cormac Square
Belfast
Northern Ireland
BT2 8LA

+44 (0)757 882 9933
info@kulawe.com
www.kulawe.com

Company Number: NI604010
VAT Number : GB 122 6319 42

@mohae
Copy link
Contributor

mohae commented Feb 20, 2015

@owenwaller Windows does not allow open files to be deleted.

I added a CloseLogFile() function that to jww that checks to see if the io.Writer is an *os.File and closes the file if it is. The LogHandle is set to ioutil.Discard prior to file.Close().

With this change, I was still getting "the process cannot access the file because it is being used by another process" error. This error persisted regardless of what hoops I had jww jump through. Also, some files would be removeable. Defering the Close seemed to affect the success rate, but numerours files were still being flagged as in use.

I added a test to jww to test the new close function and the test was able to remove the closed LogFile.

There is something going on with the code in utils_test.go that is contributing to this issue. I'm not sure what it is yet.

@mohae
Copy link
Contributor

mohae commented Feb 20, 2015

@owenwaller I think you have some extraneous packages in your repo. Notice the "cannot find package..." errors. I don't think those are in hugo. Also, Hugo builds fine for me on Windows.

@bep
Copy link
Member

bep commented Feb 20, 2015

Had a quick look at this (hate puzzles).

@mohae - you can do jww.LogHandle.(*os.File).Close() - and you don't have to modify the jww code.

But it will not fix this issue.

My best guess is some Windows antivirus scanner issue.

Maybe add this for now?

if runtime.GOOS == "windows" {
        t.Skip("No Windows")
}

@mohae
Copy link
Contributor

mohae commented Feb 20, 2015

@bep, good point about closing the file from the test. I overlooked the fact that LogHandle is exported.

Disabling my antivirus did not affect the outcome. In addition, my test in jww properly removes the test log file after calling CloseLogFile() so I don't think that's the issue.

Using runtime to separate out behavior for windows will work for now, but then either this functionality doesn't get tested for windows or the files remain in the temp directory. While I would prefer not to leave files in temp, it wouldn't be the first process to do so; even chrome does so.

I will take another look at utils_test.go later today, when I have some additional time. I'm thinking that all of the function calls along with the various go routines that test creates still being in flight is contributing to this since creating simpler test situations work as expected.

@owenwaller
Copy link
Contributor Author

FWIW if you've not noticed yet, Appveyor has upgraded the installed go
to the current v1.4.2 windows/amd64

I have to say I'm impressed, The ticket suggested next week :)

Owen

On Thu, 2015-02-19 at 13:32 -0800, Joel Scoble wrote:

I added a request for AppVeyor to upgrade to 1.4 on
http://help.appveyor.com/discussions/problems/1215-go-14-support. They
said they would update this week.

But that won't address the failures within these tests on Windows.

First I added a sleep to teardown() before removing the file, which
didn't work.

I then:

  * Created a tempDir using init() and placed all the testing
    logfiles in there.
  * Changed teardown() do an os.RemoveAll() on the temp directory.
  * Changed setup() to return the *os.File in addition to the
    filename.
  * Added a f.Close() to the returned file handle in the testing
    code.
  * Added jww.DiscardLogging() before calling `f.Close().
  * Created a main test function which ran the tests and after all
    tests were run called teardown().

These changes, which were made incrementally, also failed due to the
files still being in use.

The root of the problem is that jww never closes any files. It relies
on the program exiting to close the filies. It doesn't appear that
these tests will pass on Windows until there is a way of telling jww
to close its log files.

For jww, I think that calling DiscardLogging() might be an appropriate
place to close files, or any other function which allows for the
Handle to be changed.

Regardless, I don't think there is a way for these tests, as currently
written, to pass until there are changes on the jww side.


Reply to this email directly or view it on GitHub.

Dr. Owen Waller
Head of Development
Kulawe Limited
Forsyth House
Cormac Square
Belfast
Northern Ireland
BT2 8LA

+44 (0)757 882 9933
info@kulawe.com
www.kulawe.com

Company Number: NI604010
VAT Number : GB 122 6319 42

@owenwaller
Copy link
Contributor Author

Update:

Well the good news is this is this is all now fixed, and everything is building on Appveyor now :). But there are a few subtle things you need to be aware of if you are also trying to set-up Appveyor to build your own forked hugo repository.
See #920

Folks,

Ok so something s still up with my Appveyor build or my repo is somehow
completely corrupt at this point.

So if you look here:
https://ci.appveyor.com/project/owenwaller/hugo/build/1.0.36
That's my latest build and up that still fails with "cannot find package
"github.com/kr/pty""

This is after both a rebase of the upstream master onto my local master,
and a push -f master to my github repo. The rebase was completely
clean. So I am now upto date with the master branch - as my github repo
proves.

Currently my last commit is @bep's
dc7b7ef

Now, if I repeat what appveyor is doing locally on my Linux box I
actually see different behaviour.

owen@thinkpad:/tmp/go-src$ rm -rf src/
owen@thinkpad:/tmp/go-src$ mkdir src
owen@thinkpad:/tmp/go-src$ cd src/
owen@thinkpad:/tmp/go-src/src$ go get -v -t -d
github.com/owenwaller/hugo
github.com/owenwaller/hugo (download)
github.com/spf13/hugo (download)
bitbucket.org/kardianos/osext (download)
bitbucket.org/pkg/inflect (download)
github.com/BurntSushi/toml (download)
github.com/PuerkitoBio/purell (download)
github.com/opennota/urlesc (download)
github.com/dchest/cssmin (download)
github.com/eknkc/amber (download)
github.com/gorilla/websocket (download)
github.com/mitchellh/mapstructure (download)
github.com/russross/blackfriday (download)
github.com/shurcooL/sanitized_anchor_name (download)
github.com/spf13/afero (download)
github.com/spf13/cast (download)
github.com/spf13/jwalterweatherman (download)
github.com/spf13/cobra (download)
github.com/spf13/pflag (download)
github.com/spf13/fsync (download)
github.com/spf13/viper (download)
github.com/kr/pretty (download)
github.com/kr/text (download)
github.com/xordataexchange/crypt (download)
github.com/armon/consul-api (download)
github.com/coreos/go-etcd (download)
github.com/coreos/etcd (download)
Fetching https://golang.org/x/crypto/openpgp?go-get=1
Parsing meta tags from https://golang.org/x/crypto/openpgp?go-get=1
(status code 200)
get "golang.org/x/crypto/openpgp": found meta tag
main.metaImport{Prefix:"golang.org/x/crypto", VCS:"git",
RepoRoot:"https://go.googlesource.com/crypto"} at
https://golang.org/x/crypto/openpgp?go-get=1
get "golang.org/x/crypto/openpgp": verifying non-authoritative meta tag
Fetching https://golang.org/x/crypto?go-get=1
Parsing meta tags from https://golang.org/x/crypto?go-get=1 (status code
200)
golang.org/x/crypto (download)
Fetching https://gopkg.in/yaml.v2?go-get=1
Parsing meta tags from https://gopkg.in/yaml.v2?go-get=1 (status code
200)
get "gopkg.in/yaml.v2": found meta tag
main.metaImport{Prefix:"gopkg.in/yaml.v2", VCS:"git",
RepoRoot:"https://gopkg.in/yaml.v2"} at
https://gopkg.in/yaml.v2?go-get=1
gopkg.in/yaml.v2 (download)
github.com/yosssi/ace (download)
github.com/spf13/nitro (download)
Fetching https://gopkg.in/fsnotify.v0?go-get=1
Parsing meta tags from https://gopkg.in/fsnotify.v0?go-get=1 (status
code 200)
get "gopkg.in/fsnotify.v0": found meta tag
main.metaImport{Prefix:"gopkg.in/fsnotify.v0", VCS:"git",
RepoRoot:"https://gopkg.in/fsnotify.v0"} at
https://gopkg.in/fsnotify.v0?go-get=1
gopkg.in/fsnotify.v0 (download)
owen@thinkpad:/tmp/go-src/src$ cd github.com/owenwaller/hugo/
owen@thinkpad:/tmp/go-src/src/github.com/owenwaller/hugo$ go test -cover
-v ./...
# github.com/owenwaller/hugo/helpers
helpers/content_test.go:4:2: cannot find package
"github.com/stretchr/testify/assert" in any of:
    /home/owen/golang/go/src/github.com/stretchr/testify/assert (from
$GOROOT)
    /tmp/go-src/src/github.com/stretchr/testify/assert (from $GOPATH)
FAIL    github.com/owenwaller/hugo/helpers [setup failed]
# github.com/owenwaller/hugo/hugolib
helpers/content_test.go:4:2: cannot find package
"github.com/stretchr/testify/assert" in any of:
    /home/owen/golang/go/src/github.com/stretchr/testify/assert (from
$GOROOT)
    /tmp/go-src/src/github.com/stretchr/testify/assert (from $GOPATH)
FAIL    github.com/owenwaller/hugo/hugolib [setup failed]
# github.com/owenwaller/hugo/tpl
helpers/content_test.go:4:2: cannot find package
"github.com/stretchr/testify/assert" in any of:
    /home/owen/golang/go/src/github.com/stretchr/testify/assert (from
$GOROOT)
    /tmp/go-src/src/github.com/stretchr/testify/assert (from $GOPATH)
FAIL    github.com/owenwaller/hugo/tpl [setup failed]
?       github.com/owenwaller/hugo  [no test files]
?       github.com/owenwaller/hugo/bufferpool   [no test files]
=== RUN TestFixUrl
--- PASS: TestFixUrl (0.00s)
PASS
coverage: 11.7% of statements
ok      github.com/owenwaller/hugo/commands 0.009s  coverage: 11.7% of
statements
?       github.com/owenwaller/hugo/create   [no test files]
?       github.com/owenwaller/hugo/hugofs   [no test files]
?       github.com/owenwaller/hugo/livereload   [no test files]
=== RUN TestDegenerateCreatePageFrom
--- PASS: TestDegenerateCreatePageFrom (0.00s)
=== RUN TestStandaloneCreatePageFrom
--- PASS: TestStandaloneCreatePageFrom (0.00s)
=== RUN TestPageShouldRender
--- PASS: TestPageShouldRender (0.00s)
=== RUN TestPageHasFrontMatter
--- PASS: TestPageHasFrontMatter (0.00s)
=== RUN TestExtractFrontMatter
--- PASS: TestExtractFrontMatter (0.00s)
=== RUN TestExtractFrontMatterDelim
--- PASS: TestExtractFrontMatterDelim (0.00s)
PASS
coverage: 41.1% of statements
ok      github.com/owenwaller/hugo/parser   0.007s  coverage: 41.1% of
statements
=== RUN TestIgnoreDotFilesAndDirectories
--- PASS: TestIgnoreDotFilesAndDirectories (0.00s)
=== RUN TestEmptySourceFilesystem
--- PASS: TestEmptySourceFilesystem (0.00s)
=== RUN TestAddFile
--- PASS: TestAddFile (0.00s)
PASS
coverage: 39.4% of statements
ok      github.com/owenwaller/hugo/source   0.040s  coverage: 39.4% of
statements
=== RUN TestHTMLRedirectAlias
--- PASS: TestHTMLRedirectAlias (0.00s)
=== RUN TestPageTranslator
--- PASS: TestPageTranslator (0.00s)
=== RUN TestPageTranslatorBase
--- PASS: TestPageTranslatorBase (0.00s)
=== RUN TestTranslateUglyUrls
--- PASS: TestTranslateUglyUrls (0.00s)
=== RUN TestTranslateDefaultExtension
--- PASS: TestTranslateDefaultExtension (0.00s)
PASS
coverage: 49.2% of statements
ok      github.com/owenwaller/hugo/target   0.018s  coverage: 49.2% of
statements
=== RUN TestChainZeroTransformers
--- PASS: TestChainZeroTransformers (0.00s)
=== RUN TestAbsUrl
--- PASS: TestAbsUrl (0.00s)
=== RUN TestXMLAbsUrl
--- PASS: TestXMLAbsUrl (0.00s)
PASS
coverage: 87.6% of statements
ok      github.com/owenwaller/hugo/transform    0.019s  coverage: 87.6% of
statements
=== RUN TestCutUsageMessage
--- PASS: TestCutUsageMessage (0.00s)
PASS
coverage: 11.1% of statements
ok      github.com/owenwaller/hugo/utils    0.034s  coverage: 11.1% of
statements
?       github.com/owenwaller/hugo/watcher  [no test files]
owen@thinkpad:/tmp/go-src/src/github.com/owenwaller/hugo$ git branch
* master

Note: Line one of this nukes my my entire src tree under $GOPATH/src
Also as you can see this is all on the master branch in my repo - which
matches the current HEAD in the upstream repo.
Either way I still don't have a build. But this time I don't have a
build on linux or Windows.

So has anyone any idea just what is going on here and how to fix this?
Right now I am stumped.

I am tempted to nuke my github repo and fork again, but I really don't
think this will fix anything - and it'll killl of the pull request we
are all discussing along with all of these comments....

If someone wants to take 10 minutes and clone my hugo repo to see what
they get that would be very much appreciated at this point.

Thanks

Owen

On Thu, 2015-02-19 at 20:38 -0800, Joel Scoble wrote:

@owenwaller I think you have some extraneous packages in your repo.
Notice the "cannot find package..." errors. I don't think those are in
hugo. Also, Hugo builds fine for me on Windows.


Reply to this email directly or view it on GitHub.

Dr. Owen Waller
Head of Development
Kulawe Limited
Forsyth House
Cormac Square
Belfast
Northern Ireland
BT2 8LA

+44 (0)757 882 9933
info@kulawe.com
www.kulawe.com

Company Number: NI604010
VAT Number : GB 122 6319 42

@mohae
Copy link
Contributor

mohae commented Feb 20, 2015

@owenwaller the tests now pass on both Windows and Linux. The updated tests can be viewed at https://github.com/mohae/hugo/tree/utils_test. You can grab the updated code from my branch, or I can use that branch to submit a pull request. Please let me know if you want me to do so.

The problem was related to the setup/teardown functions and the way the testing library works. Eliminating those functions and moving the file creation to the test functions that were using them, and closing those files there resolved the issue.

To keep things cleaner, I created a tempDir on init() that both of the functions that create log files used. I also added a TestMain() function to run the tests from. After all of the tests are run, the tempDir is removed. Errors in TestMain and init() result in a panic.

I'm not sure that error checking is needed on the removal of the temporary directory and its files, but since that was being checked in the original teardown function, and that error was the source of these test changes, I left it in.

I also changed the name of the checkForExpectedStingOrFail() function to checkForExpectedStringOrFail() since I assumed that the Sting was erroneous.

@mohae
Copy link
Contributor

mohae commented Feb 20, 2015

I forgot to mention that these changes did not require any changes to jww due to @bep's suggestion.

@bep bep closed this Feb 20, 2015
@owenwaller
Copy link
Contributor Author

@mohae thanks, well done. Give me a day - I'm away from my laptop for
most of the day - to look a the changes and get back to you.

But you seem to be suggesting that this is some sort of interaction
between my setup/teardown functions and the go testing library.
Correct?? Can you be more specific as to why this would be an issue?

Owen

On Fri, 2015-02-20 at 15:29 -0800, Joel Scoble wrote:

@owenwaller the tests now pass on both Windows and Linux. The updated
tests can be viewed at https://github.com/mohae/hugo/tree/utils_test.
You can grab the updated code from my branch, or I can use that branch
to submit a pull request. Please let me know if you want me to do so.

The problem was related to the setup/teardown functions and the way
the testing library works. Eliminating those functions and moving the
file creation to the test functions that were using them, and closing
those files there resolved the issue.

To keep things cleaner, I created a tempDir on init() that both of the
functions that create log files used. I also added a TestMain()
function to run the tests from. After all of the tests are run, the
tempDir is removed. Errors in TestMain and init() result in a panic.

I'm not sure that error checking is needed on the removal of the
temporary directory and its files, but since that was being checked in
the original teardown function, and that error was the source of these
test changes, I left it in.

I also changed the name of the checkForExpectedStingOrFail() function
to checkForExpectedStringOrFail() since I assumed that the Sting was
erroneous.


Reply to this email directly or view it on GitHub.

Dr. Owen Waller
Head of Development
Kulawe Limited
Forsyth House
Cormac Square
Belfast
Northern Ireland
BT2 8LA

+44 (0)757 882 9933
info@kulawe.com
www.kulawe.com

Company Number: NI604010
VAT Number : GB 122 6319 42

@mohae
Copy link
Contributor

mohae commented Feb 25, 2015

@owenwaller:
One should not write tests the same way one would write the application code. Imo, writing a lot of helper functions to do work for you in tests is probably a sign that the tests are being written wrong. KISS

iirc, tests spawn go routines. The problems this code was exhibiting seemed to indicate that some go routines were still in flight while the teardown function was being executed, which is why some files could not be deleted. Moving around where the close occurred, e.g. defer vs not deferring, also affected how many files had this error. Also, runs could exhibit very minor variations.

I had thought that sleeping some before the close and removal of the test file might allow whatever process that had a handle on the file to finish and the close/removal to succeed. That was not the case.

Since I had already spent too much time trying to work out the issue, changing the way the tests were structured seemed more productive than doing further investigations to determine why those routines were still in flight and how to avoid that situation with the existing test code base.

For tests, in general, keep the code the test is running as local to that test as possible, keep things as simple as possible to achieve your testing goals, and minimize the use of helper functions within the tests.

Helper functions do have their place, and I do use them, mainly to help evaluation of results, but they should be used when necessary and not necessarily when convenient. You will notice that the functions that did remain in the updated tests were the ones that evaluated the results.

The same is true with testing libraries. I went from using GoConvey, because of all of its "conveniences" baked in, to really disliking it. Then started using stretchr/testify, but now I mainly just use the standard testing package.

The above is my opinion. It may or may not be useful. As you do more testing in Go, you will probably form your own opinions.

Also, I noticed in you tended towards very verbose function names, Go tends to lean towards less verbose naming.

I hope some of the above helps.

tychoish pushed a commit to tychoish/hugo that referenced this pull request Aug 13, 2017
Rationale: Test failing on Windows with errors like this:

    utils_test.go:177: Error: Could not remove file "f".
    Error: remove C:\Users\appveyor\AppData\Local\Temp\utils_test_747965610:
    The process cannot access the file because it is being used by another
    process.

This reverts commit 6b28e38.

Sorry for my premature merge of Pull Request gohugoio#818.
@github-actions
Copy link

github-actions bot commented Mar 4, 2022

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants