             return
         }
         
-        var trained = false
+        var processed = false
         var tries = 0
-        while(!trained) {
+        repeat {
             tries += 1
             let description = "Wait until the corpus is processed before training the customization."
             let expectation = self.expectation(description: description)

                failure: failToGetCorpusStatus) { corpus in
                    
                    if corpus.status == .analyzed {
                        trained = true
                    }
                    expectation.fulfill()
            }
            waitForExpectations()
            
            if tries > 10 {
                XCTFail("The corpus has not been processed. Please check the corpus errors.")
            }
            
            sleep(3)
        }
        
        let description2 = "Train the customization with the new corpus."
        let expectation2 = self.expectation(description: description2)

                
                if customization.status == .available {
                    trained = true
                } else if customization.status == .failed {
                    let message = "There was an error when training the customization, please " +
                    "check and fix the errors before trying again."
                    XCTFail(message)
                }
                expectation3.fulfill()
            }
            waitForExpectations()
            
            if tries > 10 {
                XCTFail("The customization is taking too long to train. Please try again later.")
            }
            
            sleep(3)
        } while(!trained)
    }
    
    // MARK: - Models
