Implementing tests that extends ServicesWebTestCase, I discovered that calling servicesGet after servicesPut causes Curl to complain about the CURLOPT_INFILE resources file disappearing.

As there seems to be no way to unset the given option in the reused curl resource, I've worked around the issue by creating a new curl resource whenever the previous request used CURLOPT_INFILE but the current doesn't. Not very elegant, but it eliminates the warning.

Comments

kylebrowning’s picture

Status: Active » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, infile_handling.patch, failed testing.

kylebrowning’s picture

Status: Needs work » Closed (won't fix)

this breaks multiple tests :/

You should just overwrite the setUp() method in your own testCaseClass

xen’s picture

Status: Closed (won't fix) » Needs work

I cannot just override setUp(), as it's the curlExec() method that's the issue.

Are you seriously suggesting that anyone that writes a service test that might trying to GETting something after PUTting/POSTing something, should override curlExec() in order to work around this issue?

kylebrowning’s picture

Status: Needs work » Closed (fixed)

No, Im saying if you subclass ServicesWebTestCase in your own tests, and write your own setUp method that includes this code

+
+    if ($this->previousExecHadInfile) {
+      // If the previous exec used CURLOPT_INFILE, we have to reinitialize curl
+      // to loose the option, as to not cause curl to complain that the file has
+      // disappeared.
+      curl_close($this->curlHandle);
+      unset($this->curlHandle);
+      $this->curlInitialize();
+    }
+    $this->previousExecHadInfile = isset($curl_options[CURLOPT_INFILE]);

Your tests will pass without warnings, and Services tests wont break.

xen’s picture

Status: Closed (fixed) » Needs work

No it wont, the setUp() method is called before each testSomething() method, but if testSomething() includes code ala:

$res = $this->servicesPost(...);
$this->assertSomethingOrOther(...);
$res = $this->servicesGet(...);
$this->assertSomething(...);
$res = $this->servicesPut(...);
$this->assertSomethingElse(...);
$res = $this->servicesGet(...);
$this->assertSomethingMore(...);

then the curlHandle *wont* be re-initialized, as setUp() isn't called in between the calls, and the warnings will occur.

kylebrowning’s picture

For some reason looking at the patch I thought your code was in the setUp method.

Im fine with this but i t needs to pass all tests and currently it introduces 12 fails and 8 exceptions.

xen’s picture

Status: Needs work » Needs review
StatusFileSize
new1.48 KB

Figured it out. When re-initializing Curl, it's cookie state got lost, loosing the session cookie. Which resulted in access denied.

New patch which uses a cookie file to store cookies between Curl sessions.

kylebrowning’s picture

Status: Needs review » Reviewed & tested by the community

There we go, thanks Xen, sorry for the miscommunication.

kylebrowning’s picture

Status: Reviewed & tested by the community » Closed (fixed)

Fixed in dev, will be in 3.4