<div dir="ltr"><a href="https://github.com/juju/testing/pull/92">https://github.com/juju/testing/pull/92</a> is a possible "fix" for this. It just panic() if it notices that the suite that was seen in SetUpSuite() is different than the one seen in AddSuiteCleanup(), and similarly for SetUp() and AddCleanup()<br><div><br></div><div>A different possibility would be to ignore "s" and only use the original pointer? Would that be a better fix?</div><div><br>John</div><div>=:-></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 17, 2016 at 8:52 AM, John Meinel <span dir="ltr"><<a href="mailto:john@arbash-meinel.com" target="_blank">john@arbash-meinel.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I came across this in the LXD test suite today, which was hard to track down, so I figured I'd let everyone know about it.<div><br></div><div>We have a nice helper in testing.IsolationSuite with "PatchValue()" that will change a global for you during the test, and then during TearDown() will cleanup the patch it made.</div><div>It turns out that if your test doesn't have a pointer receiver this fails, because the "suite" object is a copy, so when PatchValue calls AddCleanup to do s.testStack = append(...) the suite object goes away before TearDown is called.</div><div><br></div><div>You can see this with the attached test suite.</div><div><br></div><div>Example:</div><div><br></div><div>func (s mySuite) TestFoo(c *gc.C) {</div><div> // This is unsafe because s.PatchValue ends up modifying s.testStack but that attribute only exists </div><div> // for the life of the TestFoo function</div><div>  s.PatchValue(&globalVar, "newvalue")</div><div>}</div><div><br></div><div>I tried adding the attached patch so that we catch places we are using AddCleanup unsafely, but it fails a few tests I wasn't expecting, so I'm not sure if I'm actually doing the right thing.</div><div><br></div><div>John</div><div>=:-></div><div><br></div></div>
</blockquote></div><br></div>