Skip to content

Commit

Permalink
StartAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
Gekctek committed Dec 13, 2024
1 parent 7fd7e25 commit ee079dd
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
37 changes: 20 additions & 17 deletions samples/Sample.PocketIC/PocketIc.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class PocketIcServerFixture : IDisposable
public PocketIcServerFixture()
{
// Start the server for all tests
this.Server = PocketIcServer.Start(runtimeLogLevel: LogLevel.Trace, showErrorLogs: true).GetAwaiter().GetResult();
this.Server = PocketIcServer.StartAsync(runtimeLogLevel: LogLevel.Debug, showErrorLogs: true).GetAwaiter().GetResult();
}

public void Dispose()
Expand Down Expand Up @@ -121,19 +121,18 @@ public async Task HttpGateway_CounterWasm__Basic__Valid()
Assert.Equal((UnboundedUInt)0, getResponseValue);


// Add this at the "Here" comment
var processInfo = new ProcessStartInfo
{
FileName = "dfx",
Arguments = $"canister call {canisterId} inc () --network {httpGateway.Url} --identity anonymous --verbose --async",
Arguments = $"canister call {canisterId} inc () --network {httpGateway.Url} --identity anonymous --verbose",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true,
WorkingDirectory = "/home/gekctek/git/ICP.NET",
};
Debug.WriteLine("dfx " + processInfo.Arguments);
RequestId requestId;
// RequestId requestId;
using (var process = Process.Start(processInfo))
{
string output = process!.StandardOutput.ReadToEnd();
Expand All @@ -143,37 +142,41 @@ public async Task HttpGateway_CounterWasm__Basic__Valid()
// Optionally log or handle the output/error
Debug.WriteLine($"Output: {output}");
Debug.WriteLine($"Error: {error}");
requestId = new RequestId(Convert.FromHexString(output.Trim().Substring(2)));
// requestId = new RequestId(Convert.FromHexString(output.Trim().Substring(2)));
}
Debug.WriteLine("---Start-----\n\n\n\n\n\n\n\n\n\n\n");
CancellationTokenSource cts = new(TimeSpan.FromSeconds(5));

// CandidArg incResponseArg = await agent.CallAsync(canisterId, "inc", CandidArg.Empty(), cancellationToken: cts.Token);
// Assert.Equal(CandidArg.Empty(), incResponseArg);

// This alternative also doesnt work
// RequestId requestId = await agent.CallAsynchronousAsync(canisterId, "inc", CandidArg.Empty());
RequestId requestId = await agent.CallAsynchronousAsync(canisterId, "inc", CandidArg.Empty());
// ICTimestamp currentTime = await pocketIc.GetTimeAsync();
// await pocketIc.SetTimeAsync(currentTime + TimeSpan.FromSeconds(5));
// await pocketIc.TickAsync(5);

// await pocketIc.TickAsync(1);
getResponse = await agent.QueryAsync(canisterId, "get", CandidArg.Empty());
// await Task.Delay(5000);

CancellationTokenSource cts = new(TimeSpan.FromSeconds(5));
CandidArg incResponseArg = await agent.WaitForRequestAsync(canisterId, requestId, cts.Token); // Waits indefinitely here
Assert.Equal(CandidArg.Empty(), incResponseArg);

getResponse = await agent.QueryAsync(canisterId, "get", CandidArg.Empty());
getResponseArg = getResponse.ThrowOrGetReply();
getResponseValue = getResponseArg.ToObjects<UnboundedUInt>();
Assert.Equal((UnboundedUInt)1, getResponseValue);
Assert.Equal((UnboundedUInt)2, getResponseValue);

CandidArg setRequestArg = CandidArg.FromObjects((UnboundedUInt)10);
CandidArg setResponseArg = await agent.CallAsync(canisterId, "set", setRequestArg);
Assert.Equal(CandidArg.Empty(), setResponseArg);
// CandidArg setRequestArg = CandidArg.FromObjects((UnboundedUInt)10);
// cts = new(TimeSpan.FromSeconds(5));
// CandidArg setResponseArg = await agent.CallAsync(canisterId, "set", setRequestArg, cancellationToken: cts.Token);
// Assert.Equal(CandidArg.Empty(), setResponseArg);

getResponse = await agent.QueryAsync(canisterId, "get", CandidArg.Empty());
getResponseArg = getResponse.ThrowOrGetReply();
getResponseValue = getResponseArg.ToObjects<UnboundedUInt>();
Assert.Equal((UnboundedUInt)10, getResponseValue);
// await pocketIc.TickAsync();

// getResponse = await agent.QueryAsync(canisterId, "get", CandidArg.Empty());
// getResponseArg = getResponse.ThrowOrGetReply();
// getResponseValue = getResponseArg.ToObjects<UnboundedUInt>();
// Assert.Equal((UnboundedUInt)10, getResponseValue);

}
}
Expand Down
2 changes: 1 addition & 1 deletion src/PocketIC/API.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/PocketIC/PocketIcServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public async ValueTask DisposeAsync()
/// <param name="runtimeLogLevel">Outputs the runtime logs using Debug.WriteLine(...) with the specified log level. Null value disables the logging</param>
/// <param name="showErrorLogs">Outputs the error logs using Debug.WriteLine(...)</param>
/// <returns>The instance of the PocketIcServer with the running process</returns>
public static async Task<PocketIcServer> Start(
public static async Task<PocketIcServer> StartAsync(
LogLevel? runtimeLogLevel = null,
bool showErrorLogs = true
)
Expand Down
2 changes: 1 addition & 1 deletion test/PocketIC.Tests/PocketIcServerFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class PocketIcServerFixture : IDisposable
public PocketIcServerFixture()
{
// Start the server for all tests
this.Server = PocketIcServer.Start(runtimeLogLevel: LogLevel.Debug).GetAwaiter().GetResult();
this.Server = PocketIcServer.StartAsync(runtimeLogLevel: LogLevel.Debug).GetAwaiter().GetResult();
}

public void Dispose()
Expand Down

0 comments on commit ee079dd

Please sign in to comment.