Skip to content

Commit

Permalink
Correct where WithRetry decorator is applied
Browse files Browse the repository at this point in the history
A TestCase.subTest() context manager will swallow exceptions, so
applying @WithRetry on the entire test does not work.
Instead, it needs to be applied on whatever the subTest is doing.
  • Loading branch information
bstaletic committed Dec 12, 2024
1 parent d8c3b69 commit 541391a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 35 deletions.
5 changes: 2 additions & 3 deletions ycmd/tests/clangd/subcommands_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ def FixIt_Check_AutoExpand_Resolved( results ):
} ) )


@WithRetry()
def RunRangedFixItTest( app, rng, expected, chosen_fixit = 0 ):
contents = ReadFile( PathToTestFile( 'FixIt_Clang_cpp11.cpp' ) )
args = {
Expand Down Expand Up @@ -616,7 +617,6 @@ def test_Subcommands_DefinedSubcommands( self, app ):
} )


@WithRetry()
@SharedYcmd
def test_Subcommands_ServerNotInitialized( self, app ):
for cmd in [
Expand Down Expand Up @@ -646,6 +646,7 @@ def test_Subcommands_ServerNotInitialized( self, app ):
with self.subTest( cmd = cmd ):
completer = handlers._server_state.GetFiletypeCompleter( [ 'cpp' ] )

@WithRetry()
@patch.object( completer, '_ServerIsInitialized', return_value = False )
def Test( app, cmd, *args ):
request = {
Expand Down Expand Up @@ -1177,7 +1178,6 @@ def test_Subcommands_FixIt_all( self, app ):
RunFixItTest( app, line, column, language, filepath, check )


@WithRetry()
@SharedYcmd
def test_Subcommands_FixIt_Ranged( self, app ):
for test in [
Expand Down Expand Up @@ -1237,7 +1237,6 @@ def test_Subcommands_FixIt_AlreadyResolved( self, app ):
assert_that( actual, equal_to( expected ) )


@WithRetry()
@IsolatedYcmd( { 'clangd_args': [ '-hidden-features' ] } )
def test_Subcommands_FixIt_ClangdTweaks( self, app ):
selection = {
Expand Down
42 changes: 14 additions & 28 deletions ycmd/tests/java/subcommands_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def RunHierarchyTest( app, kind, direction, location, expected, code ):
RunTest( app, test )


@WithRetry()
def RunFixItTest( app,
description,
filepath,
Expand Down Expand Up @@ -679,7 +680,6 @@ def test_Subcommands_GoToReferences_NoReferences( self, app ):
'Cannot jump to location' ) )


@WithRetry()
@IsolatedYcmd( {
'extra_conf_globlist': PathToTestFile( 'multiple_projects', '*' )
} )
Expand Down Expand Up @@ -722,14 +722,11 @@ def test_Subcommands_GoToReferences_MultipleProjects( self, app ):
'com',
'test',
'TestWidgetImpl.java' )
for desc, request, expect in [
for desc, filepath, line, column, expect in [
( 'GoToReferences works across multiple projects',
{
'command': 'GoToReferences',
'filepath': utils_java,
'line_num': 5,
'column_num': 22,
},
utils_java,
5,
22,
{
'response': requests.codes.ok,
'data': contains_inanyorder(
Expand All @@ -739,12 +736,9 @@ def test_Subcommands_GoToReferences_MultipleProjects( self, app ):
)
} ),
( 'GoToReferences works in an unrelated project at the same time',
{
'command': 'GoToReferences',
'filepath': abstract_test_widget,
'line_num': 10,
'column_num': 15,
},
abstract_test_widget,
10,
15,
{
'response': requests.codes.ok,
'data': contains_inanyorder(
Expand All @@ -755,16 +749,15 @@ def test_Subcommands_GoToReferences_MultipleProjects( self, app ):
)
} ),
]:
with self.subTest( desc = desc, request = request, expect = expect ):
with self.subTest( desc = desc,
filepath = filepath,
line = line,
column = column,
expect = expect ):
filepath = request[ 'filepath' ]
StartJavaCompleterServerWithFile( app, filepath )


RunTest( app, {
'description': desc,
'request': request,
'expect': expect
} )
RunGoToTest( app, desc, filepath, line, column, 'GoToReferences', expect )


@WithRetry()
Expand Down Expand Up @@ -1102,7 +1095,6 @@ def test_Subcommands_RefactorRename_Unicode( self, app ):



@WithRetry()
@SharedYcmd
def test_Subcommands_FixIt_SingleDiag_MultipleOption_Insertion( self, app ):
import os
Expand Down Expand Up @@ -1259,7 +1251,6 @@ def test_Subcommands_FixIt_SingleDiag_MultipleOption_Insertion( self, app ):
RunFixItTest( app, description, filepath, 19, column, fixits_for_line )


@WithRetry()
@SharedYcmd
def test_Subcommands_FixIt_SingleDiag_SingleOption_Modify( self, app ):
filepath = PathToTestFile( 'simple_eclipse_project',
Expand Down Expand Up @@ -1327,7 +1318,6 @@ def test_Subcommands_FixIt_SingleDiag_SingleOption_Modify( self, app ):
filepath, 27, 12, fixits )


@WithRetry()
@SharedYcmd
def test_Subcommands_FixIt_SingleDiag_MultiOption_Delete( self, app ):
filepath = PathToTestFile( 'simple_eclipse_project',
Expand Down Expand Up @@ -1404,7 +1394,6 @@ def test_Subcommands_FixIt_SingleDiag_MultiOption_Delete( self, app ):
filepath, 15, 29, fixits )


@WithRetry()
@SharedYcmd
def test_Subcommands_FixIt_MultipleDiags( self, app ):
for description, column, expect_fixits in [
Expand Down Expand Up @@ -1626,7 +1615,6 @@ def test_Subcommands_FixIt_Range( self, app ):
)


@WithRetry()
@SharedYcmd
def test_Subcommands_FixIt_NoDiagnostics( self, app ):
filepath = PathToTestFile( 'simple_eclipse_project',
Expand All @@ -1652,7 +1640,6 @@ def test_Subcommands_FixIt_NoDiagnostics( self, app ):
'chunks': instance_of( list ) } ) ) } ) )


@WithRetry()
@SharedYcmd
def test_Subcommands_FixIt_Unicode( self, app ):
fixits = has_entries( {
Expand Down Expand Up @@ -1720,7 +1707,6 @@ def test_Subcommands_FixIt_Unicode( self, app ):
TEST_JAVA, 13, 1, fixits )


@WithRetry()
@IsolatedYcmd()
def test_Subcommands_FixIt_InvalidURI( self, app ):
filepath = PathToTestFile( 'simple_eclipse_project',
Expand Down
5 changes: 1 addition & 4 deletions ycmd/tests/rust/subcommands_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def RunHierarchyTest( app, kind, direction, location, expected, code ):
RunTest( app, test )


@WithRetry()
def RunGoToTest( app, command, test, *, project_root = 'common' ):
folder = PathToTestFile( project_root, 'src' )
filepath = os.path.join( folder, test[ 'req' ][ 0 ] )
Expand Down Expand Up @@ -423,7 +424,6 @@ def test_Subcommands_GoToType_Basic( self, app ):
RunGoToTest( app, 'GoToType', test )


@WithRetry()
@SharedYcmd
def test_Subcommands_GoTo( self, app ):
for test, command in itertools.product(
Expand All @@ -442,7 +442,6 @@ def test_Subcommands_GoTo( self, app ):
RunGoToTest( app, command, test )


@WithRetry()
@SharedYcmd
def test_Subcommands_GoToImplementation( self, app ):
for test in [
Expand All @@ -456,7 +455,6 @@ def test_Subcommands_GoToImplementation( self, app ):
RunGoToTest( app, 'GoToImplementation', test )


@WithRetry()
@SharedYcmd
def test_Subcommands_GoToImplementation_Failure( self, app ):
RunGoToTest( app,
Expand Down Expand Up @@ -587,7 +585,6 @@ def test_Subcommands_FixIt_Basic( self, app ):
} )


@WithRetry()
@IsolatedYcmd()
def test_Subcommands_GoTo_WorksAfterChangingProject( self, app ):
filepath = PathToTestFile( 'macro', 'src', 'main.rs' )
Expand Down

0 comments on commit 541391a

Please sign in to comment.