Handle multithreaded access crashes on unit tests using generated mocks

- always dispatch receivedInvocations mutations on the main queue
This commit is contained in:
Stefan Ceriu
2024-06-13 13:21:47 +03:00
committed by Stefan Ceriu
parent 8b3141ffec
commit b8dea8ac4e
5 changed files with 912 additions and 304 deletions
+6 -2
View File
@@ -24,11 +24,15 @@ import {{ import }}
{% endset %}
{% if method.parameters.count == 1 and not hasNonEscapingClosures %}
{% call swiftifyMethodName method.selectorName %}Received{% for param in method.parameters %}{{ param.name | replace:"`","" | upperFirstLetter }} = {{ param.name | replace:"`","" }}{% endfor %}
{% call swiftifyMethodName method.selectorName %}ReceivedInvocations.append({% for param in method.parameters %}{{ param.name }}){% endfor %}
DispatchQueue.main.async {
self.{% call swiftifyMethodName method.selectorName %}ReceivedInvocations.append({% for param in method.parameters %}{{ param.name }}){% endfor %}
}
{% else %}
{% if not method.parameters.count == 0 and not hasNonEscapingClosures %}
{% call swiftifyMethodName method.selectorName %}ReceivedArguments = ({% for param in method.parameters %}{{ param.name | replace:"`","" }}: {{ param.name | replace:"`","" }}{% if not forloop.last%}, {% endif %}{% endfor %})
{% call swiftifyMethodName method.selectorName %}ReceivedInvocations.append(({% for param in method.parameters %}{{ param.name | replace:"`","" }}: {{ param.name | replace:"`","" }}{% if not forloop.last%}, {% endif %}{% endfor %}))
DispatchQueue.main.async {
self.{% call swiftifyMethodName method.selectorName %}ReceivedInvocations.append(({% for param in method.parameters %}{{ param.name | replace:"`","" }}: {{ param.name | replace:"`","" }}{% if not forloop.last%}, {% endif %}{% endfor %}))
}
{% endif %}
{% endif %}
{% endmacro %}
+6 -2
View File
@@ -24,11 +24,15 @@ import {{ import }}
{% endset %}
{% if method.parameters.count == 1 and not hasNonEscapingClosures %}
{% call swiftifyMethodName method.selectorName %}Received{% for param in method.parameters %}{{ param.name | replace:"`","" | upperFirstLetter }} = {{ param.name | replace:"`","" }}{% endfor %}
{% call swiftifyMethodName method.selectorName %}ReceivedInvocations.append({% for param in method.parameters %}{{ param.name }}){% endfor %}
DispatchQueue.main.async {
self.{% call swiftifyMethodName method.selectorName %}ReceivedInvocations.append({% for param in method.parameters %}{{ param.name }}){% endfor %}
}
{% else %}
{% if not method.parameters.count == 0 and not hasNonEscapingClosures %}
{% call swiftifyMethodName method.selectorName %}ReceivedArguments = ({% for param in method.parameters %}{{ param.name | replace:"`","" }}: {{ param.name | replace:"`","" }}{% if not forloop.last%}, {% endif %}{% endfor %})
{% call swiftifyMethodName method.selectorName %}ReceivedInvocations.append(({% for param in method.parameters %}{{ param.name | replace:"`","" }}: {{ param.name | replace:"`","" }}{% if not forloop.last%}, {% endif %}{% endfor %}))
DispatchQueue.main.async {
self.{% call swiftifyMethodName method.selectorName %}ReceivedInvocations.append(({% for param in method.parameters %}{{ param.name | replace:"`","" }}: {{ param.name | replace:"`","" }}{% if not forloop.last%}, {% endif %}{% endfor %}))
}
{% endif %}
{% endif %}
{% endmacro %}