Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration test not able to track all messages #468

Closed
mirinkinen opened this issue Jul 13, 2023 · 3 comments
Closed

Integration test not able to track all messages #468

mirinkinen opened this issue Jul 13, 2023 · 3 comments
Milestone

Comments

@mirinkinen
Copy link

There is a problem with tracking messages that are sent from ASP.NET Core middleware after controller logic. The issue is reproduced in this simple app.

The app has a MessageMiddleware that sends the BeforeMessage before the controller and AfterMessage after the controller. In between, the controller sends it own message of type ControllerMesssage.

The all_messages_are_tracked test tries to track these messages. The tracking works when controller returns plain Ok() but does not work when controller returns any kind of object, even a simple string.

@mirinkinen
Copy link
Author

After some debugging this could be some kind of problem with asynchronicity. The execution flow in the test jumps to FindSingleTrackedMessageOfType before the HandlerGraph.HandlerFor is called for the AfterMessage type.

@mirinkinen
Copy link
Author

mirinkinen commented Jul 13, 2023

I think I got this now, perhaps... The tracked session is marked as Completed always when recording a message if there isn't any TrackedConditions that prevent it.

    public void Record(
      MessageEventType eventType,
      Envelope envelope,
      string? serviceName,
      Guid uniqueNodeId,
      Exception? ex = null)
    {
      if (envelope.Message is ValueTask)
        throw new Exception("Whatcha you doing Willis?");
      if (envelope.Message is IInternalMessage || envelope.Message is IAgentCommand)
        return;
      EnvelopeHistory envelope1 = this._envelopes[envelope.Id];
      EnvelopeRecord record = new EnvelopeRecord(eventType, envelope, this._stopwatch.ElapsedMilliseconds, ex)
      {
        ServiceName = serviceName,
        UniqueNodeId = uniqueNodeId
      };
      if (this.AlwaysTrackExternalTransports || this._otherHosts.Any<WolverineRuntime>())
        envelope1.RecordCrossApplication(record);
      else
        envelope1.RecordLocally(record);
      foreach (ITrackedCondition condition in (IEnumerable<ITrackedCondition>) this._conditions)
        condition.Record(record);
      if (ex != null)
        this._exceptions.Add(ex);
      if (!this.IsCompleted())
        return;
      this.Status = TrackingStatus.Completed;
    }

The status is the TaskCompletionSource for the Task so the task is also considered as completed and the execution flow moves on.

@jeremydmiller
Copy link
Member

@mirinkinen I stumbled into this myself today while working on something completely different. The tracking was always used before on a single triggering message. In your case -- and mine -- it's able to think it's complete and trigger the task completion during the actions in the ExecuteAndWaitAsync(). I'm fixing this today to latch that. Easy money once and only once I saw a reproduction.

@jeremydmiller jeremydmiller added this to the 1.2.0 milestone Jul 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants