While debugging the reject handling, we noticed today that implements a thing that they call Lazy-Loading. Which is very weird name for something that is basically a translation cache. If you submit a translation job with a text that was already translated once (for you, I guess, not everyone) then the translation is immediately returned with status available and no job is created on the server.

We need to handle this by removing the tier == 'machine' check in the requestTranslation() call and instead only check that status is either approved or available in retrieveTranslation() (which we should rename to saveTranslation(), it doesn't retrieve anything, unlike others like Nativy).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

blueminds’s picture

Status: Active » Needs review
FileSize
17.02 KB

To actually be able to test the available status tests had to be reworked. So quite a bit of changes are made there.

Also in case we receive an available translation for an item that is already translated, we log an error message.

Berdir’s picture

Status: Needs review » Needs work

Looks good, I haven't followed the whole discussion about available/multiple callbacks that you had with Miro but I don't quite understand why it's necessary, see below.

+++ b/tmgmt_mygengo.plugin.incundefined
@@ -242,11 +241,33 @@ class TMGMTMyGengoTranslatorPluginController extends TMGMTDefaultTranslatorPlugi
+    // Handle case when translation is received in status available for a text
+    // that is already translated or accepted. We want to add an error message.
+    if ($data->status == 'available' && $data_item['#status'] != NULL && $data_item['#status'] != TMGMT_DATA_ITEM_STATE_PENDING) {
+      $state = t('approved');
+      if ($data_item['#status'] == TMGMT_DATA_ITEM_STATE_TRANSLATED) {

Can you explain why this is only done for status available and not approved?

Also, I don't really understand the reason for this. Isn't status available used only as an immediate response? I don't think the callback will ever be called with available, because if it would have been available, then it would have already been returned directly as a response to the request. I don't think the newer v2 API handles it differently, either.

+++ b/tmgmt_mygengo.testundefined
@@ -97,37 +96,32 @@ class TMGMTMyGengoTestCase extends TMGMTBaseTestCase {
-    // Verify the label/slug.
-    $this->assertEqual($data->jobs->$key->slug, $item->data['wrapper']['#label']);

Why is this removed?

+++ b/tmgmt_mygengo.testundefined
@@ -262,6 +262,110 @@ class TMGMTMyGengoTestCase extends TMGMTBaseTestCase {
+    // Create a gengo response of translated and available job.
+    // This might happen in case a translation job is created with a text
+    // that has been already translated in past.
+    $post['job'] = json_encode(tmgmt_mygengo_test_build_response_job(
+      'Hello world',
+      'Hallo Welt',
+      'available',
+      'standard',
+      $data_item_key,
+      $item->data['wrapper']['#label']
+    ));
+
+    $action = url('tmgmt_mygengo_callback', array('absolute' => TRUE));
+    $out = $this->curlExec(array(CURLOPT_URL => $action, CURLOPT_POST => TRUE, CURLOPT_POSTFIELDS => $post));

See above, I don't think available is ever used for the callback.

Instead, I suggest you mimick th real behavior by using a special #text, e.g. "Force available status" that then uses available for the immediate response.

+++ b/tmgmt_mygengo.testundefined
@@ -262,6 +262,110 @@ class TMGMTMyGengoTestCase extends TMGMTBaseTestCase {
+    // Yet create another gengo response of translated job with status

Create yet instead of Yet create.

blueminds’s picture

Status: Needs work » Needs review
FileSize
16.41 KB

I have implemented all your comments.

Regarding the available status - it is technically possible :) That is why this use case is handled. But I see your point. So we might keep it just to cover the use case, or we can just remove it to prevent future confusion of type "what does this do?". So anyway, I think the confusion is bigger deal than the one that we "might" receive such response. Therefore I removed it as it does not really bring a value.

blueminds’s picture

eh... wrong patch, sorry

Berdir’s picture

Status: Needs review » Needs work

Removing sounds fine to me.

Looks good, confirmed that the tests work locally, just one more thing then we're done :)

+++ b/tests/tmgmt_mygengo_test.moduleundefined
@@ -48,41 +49,92 @@ function tmgmt_mygengo_test_service_get_languages() {
+      // Hack to tell mock service that translation should be returned right
+      // away as available.
+      elseif (strpos($job->tier, 'available') !== FALSE) {
+        // Remove the hack-switch string from tier.
+        $job->tier = str_replace('available', '', $job->tier);
+        $body_tgt = 'available_' . $job->body_src;
+        $response->jobs[][$id] = tmgmt_mygengo_test_build_response_job($job->body_src, $body_tgt, 'available', $job->tier, $job->custom_data, $job->slug);

As I said, I suggest to rely on a specific #text to identify this. something like '#text' => 'Lazy-Loading available' and then check body_src here. That is basically the same as what mygengo does. Relying on a custom tier wouldn't work when doing UI tests because the select has a fixed set of options and it's not possible to add more from the client side.

+++ b/tests/tmgmt_mygengo_test.moduleundefined
@@ -48,41 +49,92 @@ function tmgmt_mygengo_test_service_get_languages() {
+      // Else we have submitted a job, however just return the job object

Minor, but when you're at it.. "Else" => "Otherwise".

blueminds’s picture

Status: Needs work » Needs review
FileSize
15.64 KB

Please see the patch. BTW, its cool that by your patch reviews one also learns English ;)

Berdir’s picture

Status: Needs review » Fixed

Learning english: At your service :)

Loos good. Tests are green, commited!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.