代码之家  ›  专栏  ›  技术社区  ›  Shiraz Bhaiji

运行单元(集成)测试时的ContextSwitchDeadlock

  •  0
  • Shiraz Bhaiji  · 技术社区  · 15 年前

    在测试中运行时,我们得到以下错误:

    ContextSwitchDeadlock was detected
    Message: The CLR has been unable to transition from COM context 0x344b0c0 to COM 
    context 0x344b230 for 60 seconds. The thread that owns the destination context/apartment is
    most likely either doing a non pumping wait or processing a very long running operation 
    without pumping Windows messages. This situation generally has a negative performance 
    impact and may even lead to the application becoming non responsive or memory usage 
    accumulating continually over time. To avoid this problem, all single threaded apartment 
    (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and 
    routinely pump messages during long running operations.
    

    测试对使用实体框架从数据库获取数据的服务层上的方法执行wcf调用。还可以使用entlib缓存应用程序块在服务器端缓存数据。

    在服务器端测试相同代码的测试没有错误地通过。

    1 回复  |  直到 15 年前
        1
  •  1
  •   Shiraz Bhaiji    15 年前

    发现了问题。

    我们没有正确关闭WCF代理。我们使用的是“使用”,而不是带有关闭或中止的try-catch。

    因此,一个测试中的错误将导致后续测试中试图使用同一WCF服务的ContextSwitchDeadlock。