@@ -388,51 +388,51 @@ class SwiftIpfsApiTests: XCTestCase {
388388 }
389389
390390
391- func testName( ) {
392-
393- var idHash : String = " "
394- /// Start test by storing the existing hash so we can restore it after testing.
395- let nameResolvePublish = { ( dispatchGroup: DispatchGroup ) throws -> Void in
396- let api = try IpfsApi ( host: self . hostString, port: self . hostPort)
397- try api. name. resolve ( ) {
398- result in
399-
400- // idHash = result.stringByReplacingOccurrencesOfString("/ipfs/", withString: "")
401- idHash = result. replacingOccurrences ( of: " /ipfs/ " , with: " " )
402- dispatchGroup. leave ( )
403- }
404- }
405-
406- tester ( nameResolvePublish)
391+ func testNameResolve( ) {
407392
408- let publishedPath = " /ipfs/ " + idHash
393+ let nameResolveExpectation = XCTestExpectation ( description: " testNameResolve " )
394+ let namePublishExpectation = XCTestExpectation ( description: " testNamePublish " )
395+ let nameResolve2Expectation = XCTestExpectation ( description: " testNameResolve2 " )
409396
410- let publish = { ( dispatchGroup: DispatchGroup ) throws -> Void in
397+ do {
398+
399+ var idHash : String = " "
400+ /// Start test by storing the existing hash so we can restore it after testing.
401+
411402 let api = try IpfsApi ( host: self . hostString, port: self . hostPort)
412- let multihash = try fromB58String ( idHash)
413- try api. name. publish ( hash: multihash) {
414- result in
403+ try api. name. resolve ( ) { result in
415404
416- XCTAssert ( ( result. object ? [ " Name " ] ? . string) ! == self . nodeIdString &&
417- ( result. object ? [ " Value " ] ? . string) ! == publishedPath)
418- dispatchGroup. leave ( )
419- }
420- }
421-
422- self . tester ( publish)
423-
424- let resolve = { ( dispatchGroup: DispatchGroup ) throws -> Void in
425- let api = try IpfsApi ( host: self . hostString, port: self . hostPort)
426- try api. name. resolve ( ) {
427- result in
428- XCTAssert ( result == publishedPath)
429- dispatchGroup. leave ( )
405+ idHash = result. replacingOccurrences ( of: " /ipfs/ " , with: " " )
406+
407+ nameResolveExpectation. fulfill ( )
408+
409+ let publishedPath = " /ipfs/ " + idHash
410+ let multihash = try fromB58String ( idHash)
411+
412+ try api. name. publish ( hash: multihash) { result in
413+
414+ XCTAssert ( ( result. object ? [ " Name " ] ? . string) ! == self . nodeIdString &&
415+ ( result. object ? [ " Value " ] ? . string) ! == publishedPath)
416+
417+ namePublishExpectation. fulfill ( )
418+
419+ try api. name. resolve ( ) { result in
420+ XCTAssert ( result == publishedPath)
421+ nameResolve2Expectation. fulfill ( )
422+ }
423+ }
424+
430425 }
426+
427+
428+ } catch {
429+ XCTFail ( " test failed with error \( error) " )
431430 }
432431
433- self . tester ( resolve )
432+ wait ( for : [ nameResolveExpectation , namePublishExpectation , nameResolve2Expectation ] , timeout : 5.0 )
434433 }
435434
435+
436436 // Fails on timeout because the api doesn't return – it keeps looking.
437437 func testDhtFindProvs( ) {
438438
0 commit comments