OptrisOptrisDocumentation

Documentation/OTC SDK/Optris.Sdk — C# API referencev12.0

FaultInjection

public static class FaultInjection

Makes things go wrong on purpose, so that an application can test what it does when they go wrong for real.

Nothing here is a feature of a camera, and nothing here works on one. Every call refuses a real device and acts only on a simulated camera, so a call that reached a production build throws the first time it runs against hardware instead of doing damage quietly.

Why it is in a namespace of its own. Because a using Optris.Sdk; must not be enough to reach it. Writing using Optris.Sdk.Testing; at the top of a file is a deliberate act, and FaultInjection is not a name anybody reaches for by accident while looking for ThermalCamera.Reconnect. The naming was the whole risk in adding this at all: the one thing worse than having no test seam is an application shipping against one.

What it is for. Until this existed, nothing an application could call made a camera drop. So an application could hand its recovery to ThermalCamera.EnableAutoReconnect(…) and then have no way to test its own use of it short of pulling a cable by hand, which no build server can do. Every integrator unplugged something.

FaultInjection: methods

public static void FakeConnectionEvent(ThermalCamera camera, ConnectionStatus status, string message = "")

Pretend a camera's link changed state, without anything having happened to it.

Hands the camera the event a dropped, stalled or failed link would have produced, through the same internal entry point a real camera's engine publishes through, so everything downstream behaves exactly as it would have: ThermalCamera.ConnectionStatus changes, the handler given to ThermalCamera.OnConnectionStatus(…) runs, and if ThermalCamera.EnableAutoReconnect(…) is in force the SDK's recovery starts and publishes ReconnectPhase.Started and the rest to the handler given to ThermalCamera.OnReconnect(…).

It does not make the camera come back. A simulated camera has no device to re-open, so the SDK's attempts against it fail and the schedule runs to ReconnectPhase.GaveUp. That is the right shape for testing what your application shows during an outage and when recovery is abandoned, and the wrong tool for testing what it does when a camera returns, which needs a simulated camera that genuinely re-opens, and is a separate feature that does not exist yet.

Example

camera.EnableAutoReconnect();
camera.OnReconnect(e => stages.Add(e.Phase));

FaultInjection.FakeConnectionLost(camera, "the test pulled it");

// Your handler now runs, because your test asked it to.
public static void FakeConnectionFailed(ThermalCamera camera, string message = "a faked failure")

Pretend an open or the acquisition thread failed. Shorthand for FaultInjection.FakeConnectionEvent(…) with ConnectionStatus.Failed.

  • camera: The simulated camera to lie to.
  • message: Detail carried to the handler.
public static void FakeConnectionLost(ThermalCamera camera, string message = "a faked connection loss")

Pretend the camera's link was lost. Shorthand for FaultInjection.FakeConnectionEvent(…) with ConnectionStatus.Lost.

  • camera: The simulated camera to lie to.
  • message: Detail carried to the handler.
public static void FakeConnectionStalled(ThermalCamera camera, string message = "a faked stall")

Pretend the camera stopped sending frames while still being open. Shorthand for FaultInjection.FakeConnectionEvent(…) with ConnectionStatus.Stalled.

  • camera: The simulated camera to lie to.
  • message: Detail carried to the handler.