tests/test-duplicateoptions.py
author Matt Harbison <matt_harbison@yahoo.com>
Mon, 22 May 2017 21:45:02 -0400
changeset 32677 f840b2621cce
parent 32291 bd872f64a8ba
child 33723 5b2f331d0a33
permissions -rw-r--r--
killdaemons: close pid file before killing processes With #serve enabled on Windows, I was getting occasional stacktraces like this: Errored test-hgweb-json.t: Traceback (most recent call last): File "./run-tests.py", line 724, in run self.tearDown() File "./run-tests.py", line 805, in tearDown killdaemons(entry) File "./run-tests.py", line 540, in killdaemons logfn=vlog) File "...\tests\killdaemons.py", line 94, in killdaemons os.unlink(pidfile) WindowsError: [Error 32] The process cannot access the file because it is being used by another process: '...\\hgtests.zmpqj3\\child80\\daemon.pids' Adrian suggested using util.posixfile, which works. However, the 'mercurial' package isn't in sys.path when invoking run-tests.py, and it isn't clear that hacking[1] it in is a good thing (especially for test-run-tests.t, which uses an installation in a temp folder). I tried using ProcessMonitor to figure out what the other process is, but that monitoring slows things down to such a degree that the issue doesn't occur. I was ready to blame the virus scanner, but it happens without that too. Looking at the code, I don't see anything that would have the pid file open. But I was able to get through about 20 full test runs without an issue with this minor change, whereas before it was pretty certain to hit this at least once in two or three runs. [1] https://www.mercurial-scm.org/pipermail/mercurial-devel/2017-May/097907.html
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28740
e8ecd1aa3f6c py3: use print_function in test-duplicateoptions.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28739
diff changeset
     1
from __future__ import absolute_import, print_function
14449
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
     2
import os
28739
d289b8847f23 py3: use absolute_import in test-duplicateoptions.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 20622
diff changeset
     3
from mercurial import (
d289b8847f23 py3: use absolute_import in test-duplicateoptions.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 20622
diff changeset
     4
    commands,
d289b8847f23 py3: use absolute_import in test-duplicateoptions.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 20622
diff changeset
     5
    extensions,
28804
ce49c8d4f0bb test-duplicateoptions: alias ui as uimod
Yuya Nishihara <yuya@tcha.org>
parents: 28740
diff changeset
     6
    ui as uimod,
28739
d289b8847f23 py3: use absolute_import in test-duplicateoptions.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 20622
diff changeset
     7
)
14449
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
     8
32291
bd872f64a8ba cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents: 30559
diff changeset
     9
ignore = {'highlight', 'win32text', 'factotum'}
14449
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    10
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    11
if os.name != 'nt':
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    12
    ignore.add('win32mbcs')
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    13
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    14
disabled = [ext for ext in extensions.disabled().keys() if ext not in ignore]
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    15
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    16
hgrc = open(os.environ["HGRCPATH"], 'w')
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    17
hgrc.write('[extensions]\n')
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    18
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    19
for ext in disabled:
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    20
    hgrc.write(ext + '=\n')
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    21
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    22
hgrc.close()
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    23
30559
d83ca854fa21 ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents: 28804
diff changeset
    24
u = uimod.ui.load()
14449
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    25
extensions.loadall(u)
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    26
15099
b1f49efeab65 test: test for options duplicate with global options
Simon Heimberg <simohe@besonet.ch>
parents: 14762
diff changeset
    27
globalshort = set()
b1f49efeab65 test: test for options duplicate with global options
Simon Heimberg <simohe@besonet.ch>
parents: 14762
diff changeset
    28
globallong = set()
b1f49efeab65 test: test for options duplicate with global options
Simon Heimberg <simohe@besonet.ch>
parents: 14762
diff changeset
    29
for option in commands.globalopts:
b1f49efeab65 test: test for options duplicate with global options
Simon Heimberg <simohe@besonet.ch>
parents: 14762
diff changeset
    30
    option[0] and globalshort.add(option[0])
b1f49efeab65 test: test for options duplicate with global options
Simon Heimberg <simohe@besonet.ch>
parents: 14762
diff changeset
    31
    option[1] and globallong.add(option[1])
b1f49efeab65 test: test for options duplicate with global options
Simon Heimberg <simohe@besonet.ch>
parents: 14762
diff changeset
    32
14449
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    33
for cmd, entry in commands.table.iteritems():
15099
b1f49efeab65 test: test for options duplicate with global options
Simon Heimberg <simohe@besonet.ch>
parents: 14762
diff changeset
    34
    seenshort = globalshort.copy()
b1f49efeab65 test: test for options duplicate with global options
Simon Heimberg <simohe@besonet.ch>
parents: 14762
diff changeset
    35
    seenlong = globallong.copy()
14449
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    36
    for option in entry[1]:
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    37
        if (option[0] and option[0] in seenshort) or \
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    38
           (option[1] and option[1] in seenlong):
28740
e8ecd1aa3f6c py3: use print_function in test-duplicateoptions.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28739
diff changeset
    39
            print("command '" + cmd + "' has duplicate option " + str(option))
14449
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    40
        seenshort.add(option[0])
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    41
        seenlong.add(option[1])