@@ -37,7 +37,7 @@ public int Run(ParseResult parseResult)
37
37
38
38
// User can decide what the degree of parallelism should be
39
39
// If not specified, we will default to the number of processors
40
- if ( ! int . TryParse ( parseResult . GetValue ( TestCommandParser . DegreeOfParallelism ) , out int degreeOfParallelism ) )
40
+ if ( ! int . TryParse ( parseResult . GetValue ( TestCommandParser . MaxParallelTestModules ) , out int degreeOfParallelism ) )
41
41
degreeOfParallelism = Environment . ProcessorCount ;
42
42
43
43
if ( ContainsHelpOption ( _args ) )
@@ -64,12 +64,15 @@ public int Run(ParseResult parseResult)
64
64
_namedPipeConnectionLoop = Task . Run ( async ( ) => await WaitConnectionAsync ( _cancellationToken . Token ) ) ;
65
65
66
66
bool containsNoBuild = parseResult . UnmatchedTokens . Any ( token => token == CliConstants . NoBuildOptionKey ) ;
67
+ List < string > msbuildCommandlineArgs = [ $ "-t:{ ( containsNoBuild ? string . Empty : "Build;" ) } _GetTestsProject",
68
+ $ "-p:GetTestsProjectPipeName={ _pipeNameDescription . Name } ",
69
+ "-verbosity:q" ] ;
67
70
68
- ForwardingAppImplementation msBuildForwardingApp = new (
69
- GetMSBuildExePath ( ) ,
70
- [ $ "-t: { ( containsNoBuild ? string . Empty : "Build;" ) } _GetTestsProject" ,
71
- $ "-p:GetTestsProjectPipeName= { _pipeNameDescription . Name } " ,
72
- "-verbosity:q" ] ) ;
71
+ AddAdditionalMSBuildParameters ( parseResult , msbuildCommandlineArgs ) ;
72
+
73
+ VSTestTrace . SafeWriteTrace ( ( ) => $ "MSBuild command line arguments: { msbuildCommandlineArgs } " ) ;
74
+
75
+ ForwardingAppImplementation msBuildForwardingApp = new ( GetMSBuildExePath ( ) , msbuildCommandlineArgs ) ;
73
76
int testsProjectResult = msBuildForwardingApp . Execute ( ) ;
74
77
75
78
if ( testsProjectResult != 0 )
@@ -89,13 +92,19 @@ public int Run(ParseResult parseResult)
89
92
return 0 ;
90
93
}
91
94
95
+ private static void AddAdditionalMSBuildParameters ( ParseResult parseResult , List < string > parameters )
96
+ {
97
+ string msBuildParameters = parseResult . GetValue ( TestCommandParser . AdditionalMSBuildParameters ) ;
98
+ parameters . AddRange ( ! string . IsNullOrEmpty ( msBuildParameters ) ? msBuildParameters . Split ( " " , StringSplitOptions . RemoveEmptyEntries ) : [ ] ) ;
99
+ }
100
+
92
101
private async Task WaitConnectionAsync ( CancellationToken token )
93
102
{
94
103
try
95
104
{
96
105
while ( true )
97
106
{
98
- NamedPipeServer namedPipeServer = new ( _pipeNameDescription , OnRequest , NamedPipeServerStream . MaxAllowedServerInstances , token ) ;
107
+ NamedPipeServer namedPipeServer = new ( _pipeNameDescription , OnRequest , NamedPipeServerStream . MaxAllowedServerInstances , token , skipUnknownMessages : true ) ;
99
108
namedPipeServer . RegisterAllSerializers ( ) ;
100
109
101
110
await namedPipeServer . WaitConnectionAsync ( token ) ;
@@ -109,32 +118,60 @@ private async Task WaitConnectionAsync(CancellationToken token)
109
118
}
110
119
catch ( Exception ex )
111
120
{
112
- VSTestTrace . SafeWriteTrace ( ( ) => ex . ToString ( ) ) ;
113
- throw ;
121
+ if ( VSTestTrace . TraceEnabled )
122
+ {
123
+ VSTestTrace . SafeWriteTrace ( ( ) => ex . ToString ( ) ) ;
124
+ }
125
+
126
+ Environment . FailFast ( ex . ToString ( ) ) ;
114
127
}
115
128
}
116
129
117
130
private Task < IResponse > OnRequest ( IRequest request )
118
131
{
119
- if ( TryGetModulePath ( request , out string modulePath ) )
132
+ try
120
133
{
121
- _testApplications [ modulePath ] = new TestApplication ( modulePath , _pipeNameDescription . Name , _args ) ;
122
- // Write the test application to the channel
123
- _actionQueue . Enqueue ( _testApplications [ modulePath ] ) ;
134
+ if ( TryGetModulePath ( request , out string modulePath ) )
135
+ {
136
+ _testApplications [ modulePath ] = new TestApplication ( modulePath , _pipeNameDescription . Name , _args ) ;
137
+ // Write the test application to the channel
138
+ _actionQueue . Enqueue ( _testApplications [ modulePath ] ) ;
124
139
125
- return Task . FromResult ( ( IResponse ) VoidResponse . CachedInstance ) ;
126
- }
140
+ return Task . FromResult ( ( IResponse ) VoidResponse . CachedInstance ) ;
141
+ }
127
142
128
- if ( TryGetHelpResponse ( request , out CommandLineOptionMessages commandLineOptionMessages ) )
129
- {
130
- var testApplication = _testApplications [ commandLineOptionMessages . ModulePath ] ;
131
- Debug . Assert ( testApplication is not null ) ;
132
- testApplication . OnCommandLineOptionMessages ( commandLineOptionMessages ) ;
143
+ if ( TryGetHelpResponse ( request , out CommandLineOptionMessages commandLineOptionMessages ) )
144
+ {
145
+ var testApplication = _testApplications [ commandLineOptionMessages . ModulePath ] ;
146
+ Debug . Assert ( testApplication is not null ) ;
147
+ testApplication . OnCommandLineOptionMessages ( commandLineOptionMessages ) ;
148
+
149
+ return Task . FromResult ( ( IResponse ) VoidResponse . CachedInstance ) ;
150
+ }
151
+
152
+ // If we don't recognize the message, log and skip it
153
+ if ( TryGetUnknownMessage ( request , out UnknownMessage unknownMessage ) )
154
+ {
155
+ if ( VSTestTrace . TraceEnabled )
156
+ {
157
+ VSTestTrace . SafeWriteTrace ( ( ) => $ "Request '{ request . GetType ( ) } ' with Serializer ID = { unknownMessage . SerializerId } is unsupported.") ;
158
+ }
159
+ return Task . FromResult ( ( IResponse ) VoidResponse . CachedInstance ) ;
160
+ }
133
161
134
- return Task . FromResult ( ( IResponse ) VoidResponse . CachedInstance ) ;
162
+ // If it doesn't match any of the above, throw an exception
163
+ throw new NotSupportedException ( $ "Request '{ request . GetType ( ) } ' is unsupported.") ;
135
164
}
165
+ catch ( Exception ex )
166
+ {
167
+ if ( VSTestTrace . TraceEnabled )
168
+ {
169
+ VSTestTrace . SafeWriteTrace ( ( ) => ex . ToString ( ) ) ;
170
+ }
136
171
137
- throw new NotSupportedException ( $ "Request '{ request . GetType ( ) } ' is unsupported.") ;
172
+ Environment . FailFast ( ex . ToString ( ) ) ;
173
+ }
174
+ return Task . FromResult ( ( IResponse ) VoidResponse . CachedInstance ) ;
138
175
}
139
176
140
177
private static bool TryGetModulePath ( IRequest request , out string modulePath )
@@ -161,9 +198,24 @@ private static bool TryGetHelpResponse(IRequest request, out CommandLineOptionMe
161
198
return false ;
162
199
}
163
200
201
+ private static bool TryGetUnknownMessage ( IRequest request , out UnknownMessage unknownMessage )
202
+ {
203
+ if ( request is UnknownMessage result )
204
+ {
205
+ unknownMessage = result ;
206
+ return true ;
207
+ }
208
+
209
+ unknownMessage = null ;
210
+ return false ;
211
+ }
212
+
164
213
private void OnErrorReceived ( object sender , ErrorEventArgs args )
165
214
{
166
- VSTestTrace . SafeWriteTrace ( ( ) => args . ErrorMessage ) ;
215
+ if ( VSTestTrace . TraceEnabled )
216
+ {
217
+ VSTestTrace . SafeWriteTrace ( ( ) => args . ErrorMessage ) ;
218
+ }
167
219
}
168
220
169
221
private static bool ContainsHelpOption ( IEnumerable < string > args ) => args . Contains ( CliConstants . HelpOptionKey ) || args . Contains ( CliConstants . HelpOptionKey . Substring ( 0 , 2 ) ) ;
0 commit comments