Skip to content

Commit 577c187

Browse files
committed
fix tests
1 parent 37e3b6f commit 577c187

2 files changed

Lines changed: 18 additions & 59 deletions

File tree

src/Couchbase.Analytics/Internal/AnalyticsService.cs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -288,13 +288,8 @@ public async Task<QueryHandle> StartQueryAsync(string statement, StartQueryOptio
288288
throw new AnalyticsException("Server response is missing required 'requestID' or 'handle' fields.", errorContext);
289289
}
290290

291-
// Strip the leading path prefix from the handle
292-
var handle = handlePath.StartsWith("/api/v1/request/status/")
293-
? handlePath["/api/v1/request/status/".Length..]
294-
: handlePath;
295-
296-
LogAsyncStartQuerySucceeded(_logger, options.ClientContextId, _redactor.SystemData(handle), _redactor.SystemData(requestId), (int)response.StatusCode);
297-
return new QueryHandle(handle, requestId, this);
291+
LogAsyncStartQuerySucceeded(_logger, options.ClientContextId, _redactor.SystemData(handlePath), _redactor.SystemData(requestId), (int)response.StatusCode);
292+
return new QueryHandle(handlePath, requestId, this);
298293
}
299294
catch (HttpRequestException httpRequestException)
300295
{
@@ -335,7 +330,10 @@ public async Task<QueryHandle> StartQueryAsync(string statement, StartQueryOptio
335330
var timeout = _clusterOptions.TimeoutOptions.DispatchTimeout;
336331
var httpClient = CreateHttpClient(timeout);
337332

338-
var statusUri = new Uri(_baseUri, $"api/v1/request/status/{handle.RequestId}/{handle.Handle}");
333+
var statusUri = Uri.TryCreate(handle.Handle, UriKind.Absolute, out var absUri)
334+
? absUri
335+
: new Uri(_baseUri, handle.Handle);
336+
339337
var request = new HttpRequestMessage(HttpMethod.Get, statusUri);
340338

341339
LogFetchStatusRequest(_logger, _redactor.SystemData(statusUri), _redactor.SystemData(handle.Handle));
@@ -393,12 +391,7 @@ public async Task<QueryHandle> StartQueryAsync(string statement, StartQueryOptio
393391
throw new InvalidOperationException("Query status indicates success but no result handle was provided by the server.");
394392
}
395393

396-
// Strip the leading path prefix to get just the handle portion
397-
var handlePath = resultHandle.StartsWith("/api/v1/request/result/")
398-
? resultHandle["/api/v1/request/result/".Length..]
399-
: resultHandle;
400-
401-
return new QueryResultHandle(handlePath, handle.RequestId, this);
394+
return new QueryResultHandle(resultHandle, handle.RequestId, this);
402395
}
403396
catch (TaskCanceledException taskCanceledEx)
404397
{
@@ -412,7 +405,10 @@ public async Task<IQueryResult> FetchResultsAsync(string requestId, string handl
412405
var httpClient = CreateHttpClient(timeout);
413406
var deserializer = options.Deserializer ?? _clusterOptions.Deserializer;
414407

415-
var resultUri = new Uri(_baseUri, $"api/v1/request/result/{handlePath}");
408+
var resultUri = Uri.TryCreate(handlePath, UriKind.Absolute, out var absUri)
409+
? absUri
410+
: new Uri(_baseUri, handlePath);
411+
416412
var request = new HttpRequestMessage(HttpMethod.Get, resultUri);
417413

418414
LogFetchResultsRequest(_logger, _redactor.SystemData(resultUri), _redactor.SystemData(handlePath));
@@ -457,7 +453,10 @@ public async Task DiscardResultsAsync(string requestId, string handlePath, Disca
457453
var timeout = _clusterOptions.TimeoutOptions.DispatchTimeout;
458454
var httpClient = CreateHttpClient(timeout);
459455

460-
var resultUri = new Uri(_baseUri, $"api/v1/request/result/{handlePath}");
456+
var resultUri = Uri.TryCreate(handlePath, UriKind.Absolute, out var absUri)
457+
? absUri
458+
: new Uri(_baseUri, handlePath);
459+
461460
var request = new HttpRequestMessage(HttpMethod.Delete, resultUri);
462461

463462
LogDiscardResultsRequest(_logger, _redactor.SystemData(resultUri), _redactor.SystemData(handlePath));

tests/Couchbase.Analytics.FunctionalTests/AsyncAnalyticsTests.cs

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ public async Task Test_AsyncAnalytics_EndToEnd_Cluster()
3434
Assert.NotNull(handle);
3535
Assert.NotNull(handle.Handle);
3636
Assert.NotNull(handle.RequestId);
37+
38+
_outputHelper.WriteLine($"Handle: {handle.Handle}");
39+
_outputHelper.WriteLine($"RequestId: {handle.RequestId}");
3740

3841
// 2. Poll for the result handle
3942
QueryResultHandle? resultHandle = null;
@@ -63,49 +66,6 @@ public async Task Test_AsyncAnalytics_EndToEnd_Cluster()
6366
Assert.Equal(100, results.MetaData.Metrics?.ResultCount);
6467
}
6568

66-
[Fact]
67-
public async Task Test_AsyncAnalytics_EndToEnd_Scope()
68-
{
69-
var statement = "select i from array_range(1, 10) as i;";
70-
var queryOptions = new StartQueryOptions()
71-
{
72-
QueryTimeout = TimeSpan.FromSeconds(30)
73-
};
74-
75-
var scope = _simpleFixture.Cluster.Database("default").Scope("default");
76-
77-
// 1. Start the query on the scope
78-
var handle = await scope.StartQueryAsync(statement, queryOptions);
79-
Assert.NotNull(handle);
80-
Assert.NotNull(handle.Handle);
81-
82-
// 2. Poll for the result handle
83-
QueryResultHandle? resultHandle = null;
84-
for (int i = 0; i < 20; i++)
85-
{
86-
resultHandle = await handle.FetchResultHandleAsync(new FetchResultHandleOptions());
87-
if (resultHandle != null)
88-
{
89-
break;
90-
}
91-
await Task.Delay(500);
92-
}
93-
94-
Assert.NotNull(resultHandle);
95-
96-
// 3. Fetch the results
97-
var results = await resultHandle!.FetchResultsAsync(new FetchResultsOptions());
98-
Assert.NotNull(results);
99-
100-
var count = 0;
101-
await foreach (var row in results.ConfigureAwait(false))
102-
{
103-
count++;
104-
}
105-
106-
Assert.Equal(10, count);
107-
}
108-
10969
[Fact]
11070
public async Task Test_AsyncAnalytics_Cancellation_Cluster()
11171
{

0 commit comments

Comments
 (0)