Skip to content
This repository has been archived by the owner on Oct 4, 2021. It is now read-only.

Commit

Permalink
[Test Framework] Don't proxy the TimerCounters
Browse files Browse the repository at this point in the history
Instead of passing the TimerCounters across the wire as MarshalByRefObjects and
accessing them directly by properties, wrap operations that need to be waited on
in a timer context, and do all the waiting on the MonoDevelop side
  • Loading branch information
iain holmes committed Apr 14, 2015
1 parent ac2576d commit c529f09
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,28 +285,11 @@ public bool ToggleElement (Func<AppQuery, AppQuery> query, bool active)
return session.Toggle (results [0], active);
}

static void WaitUntil (Func<bool> done, int timeout=20000, int pollStep = 200)
{
do {
if (done ()) {
return;
}

timeout -= pollStep;
Thread.Sleep (pollStep);
} while (timeout > 0);

throw new Exception ("Timed out waiting for event");
}

public void RunAndWaitForTimer (Action action, string counterName, int timeout = 20000)
{
var c = GetGlobalValue<TimerCounter> (counterName);
var tt = c.TotalTime;

AutoTestSession.TimerCounterContext context = session.CreateNewTimerContext (counterName);
action ();

WaitUntil (() => c.TotalTime > tt, timeout);
session.WaitForTimerContext (context);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,46 @@ public void WaitForNoElement (AppQuery query, int timeout)
}
}

[Serializable]
public struct TimerCounterContext {
public string CounterName;
public TimeSpan TotalTime;
};

public TimerCounterContext CreateNewTimerContext (string counterName)
{
TimerCounter tc = InstrumentationService.GetCounter (counterName) as TimerCounter;
if (tc == null) {
throw new Exception ("Unknown timer counter " + counterName);
}

TimerCounterContext context = new TimerCounterContext {
CounterName = counterName,
TotalTime = tc.TotalTime
};

return context;
}

public void WaitForTimerContext (TimerCounterContext context, int timeout = 20000, int pollStep = 200)
{
TimerCounter tc = InstrumentationService.GetCounter (context.CounterName) as TimerCounter;
if (tc == null) {
throw new Exception ("Unknown timer counter " + context.CounterName);
}

do {
if (tc.TotalTime > context.TotalTime) {
return;
}

timeout -= pollStep;
Thread.Sleep (pollStep);
} while (timeout > 0);

throw new Exception ("Timed out waiting for event");
}

public bool Select (AppResult result)
{
return result.Select ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void CreateBuildProject (string projectName, string kind, string category
Assert.IsTrue (newProject.CreateProjectInSolutionDirectory (false));
Assert.IsTrue (newProject.UseGit (true, false));

Session.RunAndWaitForTimer (() => newProject.Next(), "MonoDevelop.Ide.Counters.OpenWorkspaceItemTimer");
Session.RunAndWaitForTimer (() => newProject.Next(), "Solution opened in the IDE");

actualSolutionDirectory = GetSolutionDirectory ();

Expand Down

0 comments on commit c529f09

Please sign in to comment.