Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intermittent fatal error due to currentExampleGroup being nil #506

Closed
earltedly opened this issue Mar 24, 2016 · 14 comments
Closed

Intermittent fatal error due to currentExampleGroup being nil #506

earltedly opened this issue Mar 24, 2016 · 14 comments

Comments

@earltedly
Copy link

I'm intermittently getting a fatal error: unexpectedly found nil while unwrapping an Optional value in World+DSL.swift:58 whilst running my unit tests. The value which is nil is currentExampleGroup.

It's only one one spec, so I'm wondering if I'm doing something wrong there. The fact it's intermittent makes it feel a bit odd though.

I was wondering if anyone has seen this before?

@morganchen12
Copy link
Contributor

This may be related to this line added in #431.

Can you share your tests?

@earltedly
Copy link
Author

Interesting - I was looking suspiciously at that line whilst trying to work out what was going on :).

I can't share the full tests unfortunately, but what I've done is extracted the structure of the tests, as I'm guessing it's that which is triggering this.

I tried pulling it out into a separate test project but couldn't reproduce the error. After delving in a bit more (printing [self class] whilst processing the specs and then also the currentExampleGroup on line 58 each time it was hit (where it crashed). It seemed like a couple of specs were being processed simultaneously somehow.

import XCTest
import Quick
import Nimble

class Spec: QuickSpec {
    override func spec() {
        describe("string") {

            beforeEach {

            }

            context("string") {
                it("string") {

                }

                it("string") {

                }

                it("string") {

                }
            }

            context("string") {
                beforeEach {

                }

                it("string") {

                }

                it("string") {

                }

                it("string") {

                }

                context("string") {
                    beforeEach {

                    }

                    it("string") {

                    }
                    it("string") {

                    }
                }

                context("string") {
                    beforeEach {

                    }

                    it("string") {

                    }

                    it("string") {

                    }

                    context("string") {
                        beforeEach {

                        }

                        it("string") {

                        }

                        it("string") {

                        }
                    }
                }

                context("string") {
                    beforeEach {

                    }

                    it("string") {

                    }

                    it("string") {

                    }

                    it("string") {

                    }
                }
            }
        }
    }
}

@briancroom
Copy link
Member

@earltedly Do you think you would be able to share the backtrace you see at the time that the crash occurs?

@mstritt-ka
Copy link

I also get the same problem intermittently, here is my stack trace:

In Xcode, these stacktrace frames correspond to:
frame 4 - Last closing curly brace of the beforeEach for ".MYTEST" inside of MYCLASSSpec.swift
frame 10 - Last closing curly brace of ".MYTEST" inside of MYCLASSSpec.swift

`thread #1: tid = 0x141827, 0x00000001160001a8 libswiftCore.dylib'function signature specialization <Arg[0] = Exploded, Arg[1] = Exploded, Arg[2] = Dead, Arg[3] = Dead> of Swift._fatalErrorMessage (Swift.StaticString, Swift.StaticString, Swift.StaticString, Swift.UInt) -> () + 40, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)

frame #0: 0x00000001160001a8 libswiftCore.dylib'function signature specialization <Arg[0] = Exploded, Arg[1] = Exploded, Arg[2] = Dead, Arg[3] = Dead> of Swift._fatalErrorMessage (Swift.StaticString, Swift.StaticString, Swift.StaticString, Swift.UInt) -> () + 40

frame #1: 0x000000012468d26b Quick'World.beforeEach(closure=0x000000012468d490 Quick'partial apply forwarder for reabstraction thunk helper from @callee_unowned @convention(block) () -> (@unowned ()) to @callee_owned () -> (@unowned ()) with unmangled suffix ".26" at World+DSL.swift, self=0x00007fa682710680) -> ()) -> () + 219 at World+DSL.swift:58

frame #2: 0x000000012468d440 Quick'@objc World.beforeEach(() -> ()) -> () + 112 at World+DSL.swift:0

frame #3: 0x0000000124679fe3 Quick'beforeEach(closure=0x0000000123d01040 MYAPPTests'partial apply forwarder for MYAPPTests.MYCLASSSpec.(spec () -> ()).(closure #17).(closure #1) at MYCLASSSpec.swift) -> ()) -> () + 195 at DSL.swift:88

frame #4: 0x0000000123d2296e MYAPPTests'MYCLASSSpec.(manager=0x00007fa687c07e10) -> ()).(closure #17) + 414 at MYCLASSSpec.swift:1219 [opt]

frame #5: 0x000000012467c147 Quick'thunk + 39 at DSL.swift:0

frame #6: 0x0000000124679053 Quick'thunk + 19 at Configuration.swift:0

frame #7: 0x000000012468bd4b Quick'World.describe(description=".MYTEST", flags=0 key/value pairs, closure=0x000000012468c160 Quick'partial apply forwarder for reabstraction thunk helper from @callee_unowned @convention(block) () -> (@unowned ()) to @callee_owned () -> (@unowned ()) with unmangled suffix ".8" at World+DSL.swift, self=0x00007fa682710680) -> ()) -> () + 731 at World+DSL.swift:31

frame #8: 0x000000012468c109 Quick'@objc World.describe(String, flags : [String : Bool], closure : () -> ()) -> () + 249 at World+DSL.swift:0

frame #9: 0x0000000124679b45 Quick'describe(description=".MYTEST", flags=0 key/value pairs, closure=0x0000000123cff2e0 MYAPPTests'partial apply forwarder for MYAPPTests.MYCLASSSpec.(spec () -> ()).(closure #17) at MYCLASSSpec.swift) -> ()) -> () + 405 at DSL.swift:69

frame #10: 0x0000000123cfe69c MYAPPTests'specialized MYCLASSSpec.spec() -> () + 1516 at MYCLASSSpec.swift:1251 [opt]

frame #11: 0x00000001246759fb Quick'+[QuickSpec initialize](self=MYAPPTests.MYCLASSSpec, _cmd="initialize") + 219 at QuickSpec.m:35

frame #12: 0x0000000114a93bff libobjc.A.dylib'_class_initialize + 679

frame #13: 0x0000000114a99cc5 libobjc.A.dylib'lookUpImpOrForward + 176

frame #14: 0x0000000114aa88bb libobjc.A.dylib'objc_msgSend + 187

frame #15: 0x0000000110e7b35d CoreFoundation'-[__NSSetM member:] + 77

frame #16: 0x0000000110e69af6 CoreFoundation'-[NSSet containsObject:] + 22

frame #17: 0x00000001232ba1dc XCTest'+[XCTestCase(RuntimeUtilities) allSubclasses] + 159

frame #18: 0x00000001232820ed XCTest'+[XCTestSuite _suiteForBundleCache] + 175

frame #19: 0x0000000123283450 XCTest'-[XCTestSuite _initWithTestConfiguration:] + 1227

frame #20: 0x0000000123283674 XCTest'+[XCTestSuite testSuiteForTestConfiguration:] + 50

frame #21: 0x000000012326f979 XCTest'-[XCTestDriver _runSuite] + 233

frame #22: 0x00000001232707d1 XCTest'-[XCTestDriver _checkForTestManager] + 259

frame #23: 0x00000001232baa9a XCTest'_XCTestMain + 628

frame #24: 0x0000000110e7a2ec CoreFoundation'__CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12

frame #25: 0x0000000110e6ff75 CoreFoundation'__CFRunLoopDoBlocks + 341

frame #26: 0x0000000110e6f6d2 CoreFoundation'__CFRunLoopRun + 850

frame #27: 0x0000000110e6f0f8 CoreFoundation'CFRunLoopRunSpecific + 488

frame #28: 0x000000011842cad2 GraphicsServices'GSEventRunModal + 161

frame #29: 0x0000000112b29f09 UIKit'UIApplicationMain + 171

frame #30: 0x000000010ef92491 MYAPP'main(argc=5, argv=0x00007fff510ad340) + 129 at main.m:16

frame #31: 0x000000011654792d libdyld.dylib'start + 1`

@briancroom
Copy link
Member

Ah, I didn't really intend to have GitHub automatically close this when I merged #517. However I do hope that it is fixed now on master!

@earltedly @mstritt-ka could you check if you're still seeing this with Quick's master branch?

@mstritt-ka
Copy link

While 0.9.2 continues to have the same problem, pulling directly from Github does seem to fix it (I haven't seen the problem since I pulled directly).

Thank you,
Michael.

@pvandyk
Copy link

pvandyk commented Jun 17, 2016

@briancroom We are using CocoaPods to pull in 0.9.2 of Quick and are receiving this error in our tests. Is a fix still in the works?

@modocache modocache reopened this Jun 17, 2016
@modocache
Copy link
Member

For those of you still experiencing this crash, could I trouble you to post some additional information? Our test suite doesn't seem to be catching this particular error, so any information you could provide to help us track it down would be great.

For example:

  1. What version of Quick, Nimble, and Xcode are you using?
  2. Do you have any beforeSuite setup? Any QuickConfiguration setup?
  3. What's the first spec that's executed in your test suite? Could you post what it looks like (with the sensitive parts stripped out)?

@pvandyk
Copy link

pvandyk commented Jun 17, 2016

The test that fails uses Quick, Nimble and sometimes Dobby:
PODS:

  • Dobby (0.5.0)
  • Nimble (4.0.1)
  • Quick (0.9.2)

Running on Xcode Version 7.3 (7D175).

No beforeSuite or QuickConfiguration that I can see.

I put a breakpoint in each beforeEach() call in each test and on line 58 of World+DSL.swift which is crashing. It would crash in random tests. Each time I ran, a different test class caused the issue.

In fact, once, I was able to get through the whole suite of tests without crashing as I slowly clicked through each breakpoint. But then I deactivated the breakpoints and the next run, the test crashed.

For the most part, our tests look something like the following. Slight variations. Many use Dobby to mock classes:

import Quick
import Nimble

class STestClass: QuickSpec {
    override func spec() {
        describe("Test"){
            var subject:TestObject!

            beforeEach {
                subject = TestObject(objectType: "test",
                        objectFieldSpecs: [],
                        modDateFieldName: "lastModified")
            }

           it("should implicitly create LastModifiedField spec"){
                // we should have 2 implicit fields
                let modFieldSpec:Int? = subject.fields.indexOf{ $0.fieldName == subject.modDateFieldName }
                expect(modFieldSpec).toNot(beNil())
            }
        }
    }
}

@pvandyk
Copy link

pvandyk commented Jun 20, 2016

Note that if I move back to Quick (0.6.0), this error does not occur and tests run even in Xcode 7.3.

@karapigeon
Copy link

Has there been any progress on this issue since June?

@modocache
Copy link
Member

The most impactful contribution to be made here at the moment is producing a reliable reproduction of the issue. If someone could upload an example project to GitHub that reliably crashes when run, I'm confident we can fix this quickly.

@karapigeon
Copy link

I've been thinking about this a bit over the past few weeks. I'm going to try to write an example project and try as best I can to reproduce. Would appreciate it if others tried to as well.

@karapigeon karapigeon self-assigned this Oct 28, 2016
@ikesyo
Copy link
Member

ikesyo commented Jul 23, 2018

The fix was released in v0.9.3 so trying with v0.9.2 didn't make sense. Closing this old issue due to inactivity ( and should be fixed by #517).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants