我觉得它不是。我有三个集成测试在单独运行时成功,但是当并行运行时,我得到System.ArgumentException: An item with the same key has already been added.
我确信希望ScenarioContext.Current
总是提到正确的情景,但似乎感到困惑。有没有人成功地为这个类增加了线程安全性?或者我是否应该使用另一种方法在步骤文件之间共享值?
答案 0 :(得分:3)
ScenarioContext.Current source:
{{2p>正如您所看到的,它不是线程安全的 {{3P>答案 1 :(得分:1)
这似乎在SpecFlow V2中处理得更好:http://www.specflow.org/documentation/Parallel-Execution/
提取(更简单的选项):
org.elasticsearch.action.ActionRequestValidationException: Validation Failed: 1: id is missing;2: id is missing;3: id is missing;4: id is missing;5: id is missing;6: id is missing;7: id is missing;8: id is missing;9: id is missing;10: id is missing;11: id is missing;12: id is missing;13: id is missing;14: id is missing;15: id is missing;16: id is missing;17: id is missing;18: id is missing;19: id is missing;20: id is missing;21: id is missing;22: id is missing;23: id is missing;24: id is missing;25: id is missing;26: id is missing;27: id is missing;28: id is missing;29: id is missing;30: id is missing;31: id is missing;32: id is missing;33: id is missing;34: id is missing;35: id is missing;36: id is missing;37: id is missing;38: id is missing;39: id is missing;40: id is missing;41: id is missing;42: id is missing;43: id is missing;44: id is missing;45: id is missing;46: id is missing;47: id is missing;48: id is missing;49: id is missing;50: id is missing;51: id is missing;52: id is missing;53: id is missing;54: id is missing;55: id is missing;56: id is missing;57: id is missing;58: id is missing;59: id is missing;60: id is missing;61: id is missing;62: id is missing;63: id is missing;64: id is missing;65: id is missing;66: id is missing;67: id is missing;68: id is missing;69: id is missing;70: id is missing;71: id is missing;72: id is missing;73: id is missing;74: id is missing;75: id is missing;76: id is missing;77: id is missing;78: id is missing;79: id is missing;80: id is missing;81: id is missing;82: id is missing;83: id is missing;84: id is missing;85: id is missing;86: id is missing;87: id is missing;88: id is missing;89: id is missing;90: id is missing;91: id is missing;92: id is missing;93: id is missing;94: id is missing;95: id is missing;96: id is missing;97: id is missing;98: id is missing;99: id is missing;100: id is missing;101: id is missing;102: id is missing;103: id is missing;104: id is missing;105: id is missing;106: id is missing;107: id is missing;108: id is missing;109: id is missing;110: id is missing;111: id is missing;112: id is missing;113: id is missing;114: id is missing;115: id is missing;116: id is missing;117: id is missing;118: id is missing;119: id is missing;120: id is missing;121: id is missing;122: id is missing;123: id is missing;124: id is missing;125: id is missing;126: id is missing;127: id is missing;128: id is missing;129: id is missing;130: id is missing;131: id is missing;132: id is missing;133: id is missing;134: id is missing;135: id is missing;136: id is missing;137: id is missing;138: id is missing;139: id is missing;140: id is missing;141: id is missing;142: id is missing;143: id is missing;144: id is missing;145: id is missing;146: id is missing;147: id is missing;148: id is missing;149: id is missing;150: id is missing;151: id is missing;152: id is missing;153: id is missing;154: id is missing;155: id is missing;156: id is missing;157: id is missing;158: id is missing;159: id is missing;160: id is missing;161: id is missing;162: id is missing;163: id is missing;164: id is missing;165: id is missing;166: id is missing;167: id is missing;168: id is missing;169: id is missing;170: id is missing;171: id is missing;172: id is missing;173: id is missing;174: id is missing;175: id is missing;176: id is missing;177: id is missing;178: id is missing;179: id is missing;180: id is missing;181: id is missing;182: id is missing;183: id is missing;184: id is missing;185: id is missing;186: id is missing;187: id is missing;188: id is missing;189: id is missing;190: id is missing;191: id is missing;192: id is missing;193: id is missing;194: id is missing;195: id is missing;196: id is missing;197: id is missing;198: id is missing;199: id is missing;200: id is missing;201: id is missing;202: id is missing;203: id is missing;204: id is missing;205: id is missing;206: id is missing;207: id is missing;208: id is missing;209: id is missing;210: id is missing;211: id is missing;212: id is missing;213: id is missing;214: id is missing;215: id is missing;216: id is missing;217: id is missing;218: id is missing;219: id is missing;220: id is missing;221: id is missing;222: id is missing;223: id is missing;224: id is missing;225: id is missing;226: id is missing;227: id is missing;228: id is missing;229: id is missing;230: id is missing;231: id is missing;232: id is missing;233: id is missing;234: id is missing;235: id is missing;236: id is missing;237: id is missing;238: id is missing;239: id is missing;240: id is missing;241: id is missing;242: id is missing;243: id is missing;244: id is missing;245: id is missing;246: id is missing;247: id is missing;248: id is missing;249: id is missing;250: id is missing;251: id is missing;252: id is missing;253: id is missing;254: id is missing;255: id is missing;256: id is missing;257: id is missing;258: id is missing;259: id is missing;260: id is missing;261: id is missing;262: id is missing;263: id is missing;264: id is missing;265: id is missing;266: id is missing;267: id is missing;268: id is missing;269: id is missing;270: id is missing;271: id is missing;272: id is missing;273: id is missing;274: id is missing;275: id is missing;276: id is missing;277: id is missing;278: id is missing;279: id is missing;280: id is missing;281: id is missing;282: id is missing;283: id is missing;284: id is missing;285: id is missing;286: id is missing;287: id is missing;288: id is missing;289: id is missing;290: id is missing;291: id is missing;292: id is missing;293: id is missing;294: id is missing;295: id is missing;296: id is missing;297: id is missing;298: id is missing;299: id is missing;300: id is missing;301: id is missing;302: id is missing;303: id is missing;304: id is missing;305: id is missing;306: id is missing;307: id is missing;308: id is missing;309: id is missing;310: id is missing;311: id is missing;312: id is missing;313: id is missing;314: id is missing;315: id is missing;316: id is missing;317: id is missing;318: id is missing;319: id is missing;320: id is missing;321: id is missing;322: id is missing;323: id is missing;324: id is missing;325: id is missing;326: id is missing;327: id is missing;328: id is missing;329: id is missing;330: id is missing;331: id is missing;332: id is missing;333: id is missing;334: id is missing;335: id is missing;336: id is missing;337: id is missing;338: id is missing;339: id is missing;340: id is missing;341: id is missing;342: id is missing;343: id is missing;344: id is missing;345: id is missing;346: id is missing;347: id is missing;348: id is missing;349: id is missing;350: id is missing;351: id is missing;352: id is missing;353: id is missing;354: id is missing;355: id is missing;356: id is missing;357: id is missing;358: id is missing;359: id is missing;360: id is missing;361: id is missing;362: id is missing;363: id is missing;364: id is missing;365: id is missing;366: id is missing;367: id is missing;368: id is missing;369: id is missing;370: id is missing;371: id is missing;372: id is missing;373: id is missing;374: id is missing;375: id is missing;376: id is missing;377: id is missing;378: id is missing;379: id is missing;380: id is missing;381: id is missing;382: id is missing;383: id is missing;384: id is missing;385: id is missing;386: id is missing;387: id is missing;388: id is missing;389: id is missing;390: id is missing;391: id is missing;392: id is missing;393: id is missing;394: id is missing;395: id is missing;396: id is missing;397: id is missing;398: id is missing;399: id is missing;400: id is missing;401: id is missing;402: id is missing;403: id is missing;404: id is missing;405: id is missing;406: id is missing;407: id is missing;408: id is missing;409: id is missing;410: id is missing;411: id is missing;412: id is missing;413: id is missing;414: id is missing;415: id is missing;416: id is missing;417: id is missing;418: id is missing;419: id is missing;420: id is missing;421: id is missing;422: id is missing;423: id is missing;424: id is missing;425: id is missing;426: id is missing;427: id is missing;428: id is missing;429: id is missing;430: id is missing;431: id is missing;432: id is missing;433: id is missing;434: id is missing;435: id is missing;436: id is missing;437: id is missing;438: id is missing;439: id is missing;440: id is missing;441: id is missing;442: id is missing;443: id is missing;444: id is missing;445: id is missing;446: id is missing;447: id is missing;448: id is missing;449: id is missing;450: id is missing;451: id is missing;452: id is missing;453: id is missing;454: id is missing;455: id is missing;456: id is missing;457: id is missing;458: id is missing;459: id is missing;460: id is missing;461: id is missing;462: id is missing;463: id is missing;464: id is missing;465: id is missing;466: id is missing;467: id is missing;468: id is missing;469: id is missing;470: id is missing;471: id is missing;472: id is missing;473: id is missing;474: id is missing;475: id is missing;476: id is missing;477: id is missing;478: id is missing;479: id is missing;480: id is missing;481: id is missing;482: id is missing;483: id is missing;484: id is missing;485: id is missing;486: id is missing;487: id is missing;488: id is missing;489: id is missing;490: id is missing;491: id is missing;492: id is missing;493: id is missing;494: id is missing;495: id is missing;496: id is missing;497: id is missing;498: id is missing;499: id is missing;500: id is missing;501: id is missing;502: id is missing;503: id is missing;504: id is missing;505: id is missing;506: id is missing;507: id is missing;508: id is missing;509: id is missing;510: id is missing;511: id is missing;512: id is missing;513: id is missing;514: id is missing;515: id is missing;516: id is missing;517: id is missing;518: id is missing;519: id is missing;520: id is missing;521: id is missing;522: id is missing;523: id is missing;524: id is missing;525: id is missing;526: id is missing;527: id is missing;528: id is missing;529: id is missing;530: id is missing;531: id is missing;532: id is missing;533: id is missing;534: id is missing;535: id is missing;536: id is missing;537: id is missing;538: id is missing;539: id is missing;540: id is missing;541: id is missing;542: id is missing;543: id is missing;544: id is missing;545: id is missing;546: id is missing;547: id is missing;548: id is missing;549: id is missing;550: id is missing;551: id is missing;552: id is missing;553: id is missing;554: id is missing;555: id is missing;556: id is missing;557: id is missing;558: id is missing;559: id is missing;560: id is missing;561: id is missing;562: id is missing;563: id is missing;564: id is missing;565: id is missing;566: id is missing;567: id is missing;568: id is missing;569: id is missing;570: id is missing;571: id is missing;572: id is missing;573: id is missing;574: id is missing;575: id is missing;576: id is missing;577: id is missing;578: id is missing;579: id is missing;580: id is missing;581: id is missing;582: id is missing;583: id is missing;584: id is missing;585: id is missing;586: id is missing;587: id is missing;588: id is missing;589: id is missing;590: id is missing;591: id is missing;592: id is missing;593: id is missing;594: id is missing;595: id is missing;596: id is missing;597: id is missing;598: id is missing;599: id is missing;600: id is missing;601: id is missing;602: id is missing;603: id is missing;604: id is missing;605: id is missing;606: id is missing;607: id is missing;608: id is missing;609: id is missing;610: id is missing;611: id is missing;612: id is missing;613: id is missing;614: id is missing;615: id is missing;616: id is missing;617: id is missing;618: id is missing;619: id is missing;620: id is missing;621: id is missing;622: id is missing;623: id is missing;624: id is missing;625: id is missing;626: id is missing;627: id is missing;628: id is missing;629: id is missing;630: id is missing;631: id is missing;632: id is missing;633: id is missing;634: id is missing;635: id is missing;636: id is missing;637: id is missing;638: id is missing;639: id is missing;640: id is missing;641: id is missing;642: id is missing;643: id is missing;644: id is missing;645: id is missing;646: id is missing;647: id is missing;648: id is missing;649: id is missing;650: id is missing;651: id is missing;652: id is missing;653: id is missing;654: id is missing;655: id is missing;656: id is missing;657: id is missing;658: id is missing;659: id is missing;660: id is missing;661: id is missing;662: id is missing;663: id is missing;664: id is missing;665: id is missing;666: id is missing;667: id is missing;668: id is missing;669: id is missing;670: id is missing;671: id is missing;672: id is missing;673: id is missing;674: id is missing;675: id is missing;676: id is missing;677: id is missing;678: id is missing;679: id is missing;680: id is missing;681: id is missing;682: id is missing;683: id is missing;684: id is missing;685: id is missing;686: id is missing;687: id is missing;688: id is missing;689: id is missing;690: id is missing;691: id is missing;692: id is missing;693: id is missing;694: id is missing;695: id is missing;696: id is missing;697: id is missing;698: id is missing;699: id is missing;700: id is missing;701: id is missing;702: id is missing;703: id is missing;704: id is missing;705: id is missing;706: id is missing;707: id is missing;708: id is missing;709: id is missing;710: id is missing;711: id is missing;712: id is missing;713: id is missing;714: id is missing;715: id is missing;716: id is missing;717: id is missing;718: id is missing;719: id is missing;720: id is missing;721: id is missing;722: id is missing;723: id is missing;724: id is missing;725: id is missing;726: id is missing;727: id is missing;728: id is missing;729: id is missing;730: id is missing;731: id is missing;732: id is missing;733: id is missing;734: id is missing;735: id is missing;736: id is missing;737: id is missing;738: id is missing;739: id is missing;740: id is missing;741: id is missing;742: id is missing;743: id is missing;744: id is missing;745: id is missing;746: id is missing;747: id is missing;748: id is missing;749: id is missing;750: id is missing;751: id is missing;752: id is missing;753: id is missing;754: id is missing;755: id is missing;756: id is missing;757: id is missing;758: id is missing;759: id is missing;760: id is missing;761: id is missing;762: id is missing;763: id is missing;764: id is missing;765: id is missing;766: id is missing;767: id is missing;768: id is missing;769: id is missing;770: id is missing;771: id is missing;772: id is missing;773: id is missing;774: id is missing;775: id is missing;776: id is missing;777: id is missing;778: id is missing;779: id is missing;780: id is missing;781: id is missing;782: id is missing;783: id is missing;784: id is missing;785: id is missing;786: id is missing;787: id is missing;788: id is missing;789: id is missing;790: id is missing;791: id is missing;792: id is missing;793: id is missing;794: id is missing;795: id is missing;796: id is missing;797: id is missing;798: id is missing;799: id is missing;800: id is missing;801: id is missing;802: id is missing;803: id is missing;804: id is missing;805: id is missing;806: id is missing;807: id is missing;808: id is missing;809: id is missing;810: id is missing;811: id is missing;812: id is missing;813: id is missing;814: id is missing;815: id is missing;816: id is missing;817: id is missing;818: id is missing;819: id is missing;820: id is missing;821: id is missing;822: id is missing;823: id is missing;824: id is missing;825: id is missing;826: id is missing;827: id is missing;828: id is missing;829: id is missing;830: id is missing;831: id is missing;832: id is missing;833: id is missing;834: id is missing;835: id is missing;836: id is missing;837: id is missing;838: id is missing;839: id is missing;840: id is missing;841: id is missing;842: id is missing;843: id is missing;844: id is missing;845: id is missing;846: id is missing;847: id is missing;848: id is missing;849: id is missing;850: id is missing;851: id is missing;852: id is missing;853: id is missing;854: id is missing;855: id is missing;856: id is missing;857: id is missing;858: id is missing;859: id is missing;860: id is missing;861: id is missing;862: id is missing;863: id is missing;864: id is missing;865: id is missing;866: id is missing;867: id is missing;868: id is missing;869: id is missing;870: id is missing;871: id is missing;872: id is missing;873: id is missing;874: id is missing;875: id is missing;876: id is missing;877: id is missing;878: id is missing;879: id is missing;880: id is missing;881: id is missing;882: id is missing;883: id is missing;884: id is missing;885: id is missing;886: id is missing;887: id is missing;888: id is missing;889: id is missing;890: id is missing;891: id is missing;892: id is missing;893: id is missing;894: id is missing;895: id is missing;896: id is missing;897: id is missing;898: id is missing;899: id is missing;900: id is missing;901: id is missing;902: id is missing;903: id is missing;904: id is missing;905: id is missing;906: id is missing;907: id is missing;908: id is missing;909: id is missing;910: id is missing;911: id is missing;912: id is missing;913: id is missing;914: id is missing;915: id is missing;916: id is missing;917: id is missing;918: id is missing;919: id is missing;920: id is missing;921: id is missing;922: id is missing;923: id is missing;924: id is missing;925: id is missing;926: id is missing;927: id is missing;928: id is missing;929: id is missing;930: id is missing;931: id is missing;932: id is missing;933: id is missing;934: id is missing;935: id is missing;936: id is missing;937: id is missing;938: id is missing;939: id is missing;940: id is missing;941: id is missing;942: id is missing;943: id is missing;944: id is missing;945: id is missing;946: id is missing;947: id is missing;948: id is missing;949: id is missing;950: id is missing;951: id is missing;952: id is missing;953: id is missing;954: id is missing;955: id is missing;956: id is missing;957: id is missing;958: id is missing;959: id is missing;960: id is missing;961: id is missing;962: id is missing;963: id is missing;964: id is missing;965: id is missing;966: id is missing;967: id is missing;968: id is missing;969: id is missing;970: id is missing;971: id is missing;972: id is missing;973: id is missing;974: id is missing;975: id is missing;976: id is missing;977: id is missing;978: id is missing;979: id is missing;980: id is missing;981: id is missing;982: id is missing;983: id is missing;984: id is missing;985: id is missing;986: id is missing;987: id is missing;988: id is missing;989: id is missing;990: id is missing;991: id is missing;992: id is missing;993: id is missing;994: id is missing;995: id is missing;996: id is missing;997: id is missing;998: id is missing;999: id is missing;1000: id is missing;1001: id is missing;1002: id is missing;1003: id is missing;1004: id is missing;1005: id is missing;1006: id is missing;1007: id is missing;1008: id is missing;1009: id is missing;1010: id is missing;1011: id is missing;1012: id is missing;1013: id is missing;1014: id is missing;1015: id is missing;1016: id is missing;1017: id is missing;1018: id is missing;1019: id is missing;1020: id is missing;1021: id is missing;1022: id is missing;1023: id is missing;1024: id is missing;1025: id is missing;1026: id is missing;1027: id is missing;1028: id is missing;1029: id is missing;1030: id is missing;1031: id is missing;1032: id is missing;1033: id is missing;1034: id is missing;1035: id is missing;1036: id is missing;1037: id is missing;1038: id is missing;1039: id is missing;1040: id is missing;1041: id is missing;1042: id is missing;1043: id is missing;1044: id is missing;1045: id is missing;1046: id is missing;1047: id is missing;1048: id is missing;1049: id is missing;1050: id is missing;1051: id is missing;1052: id is missing;1053: id is missing;1054: id is missing;1055: id is missing;1056: id is missing;1057: id is missing;1058: id is missing;1059: id is missing;1060: id is missing;1061: id is missing;1062: id is missing;1063: id is missing;1064: id is missing;1065: id is missing;1066: id is missing;1067: id is missing;1068: id is missing;1069: id is missing;1070: id is missing;1071: id is missing;1072: id is missing;1073: id is missing;1074: id is missing;1075: id is missing;1076: id is missing;1077: id is missing;1078: id is missing;1079: id is missing;1080: id is missing;1081: id is missing;1082: id is missing;1083: id is missing;1084: id is missing;1085: id is missing;1086: id is missing;1087: id is missing;1088: id is missing;1089: id is missing;1090: id is missing;1091: id is missing;1092: id is missing;1093: id is missing;1094: id is missing;1095: id is missing;1096: id is missing;1097: id is missing;1098: id is missing;1099: id is missing;1100: id is missing;1101: id is missing;1102: id is missing;1103: id is missing;1104: id is missing;1105: id is missing;1106: id is missing;1107: id is missing;1108: id is missing;1109: id is missing;1110: id is missing;1111: id is missing;1112: id is missing;1113: id is missing;1114: id is missing;1115: id is missing;1116: id is missing;1117: id is missing;1118: id is missing;1119: id is missing;1120: id is missing;1121: id is missing;1122: id is missing;1123: id is missing;1124: id is missing;1125: id is missing;1126: id is missing;1127: id is missing;1128: id is missing;1129: id is missing;1130: id is missing;1131: id is missing;1132: id is missing;1133: id is missing;1134: id is missing;1135: id is missing;1136: id is missing;1137: id is missing;1138: id is missing;1139: id is missing;1140: id is missing;1141: id is missing;1142: id is missing;1143: id is missing;1144: id is missing;1145: id is missing;1146: id is missing;1147: id is missing;1148: id is missing;1149: id is missing;1150: id is missing;1151: id is missing;
at org.elasticsearch.action.bulk.BulkRequest.validate(BulkRequest.java:456)
at org.elasticsearch.action.TransportActionNodeProxy.execute(TransportActionNodeProxy.java:52)
at org.elasticsearch.client.transport.support.InternalTransportClient$1.doWithNode(InternalTransportClient.java:104)
at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:197)
at org.elasticsearch.client.transport.support.InternalTransportClient.execute(InternalTransportClient.java:101)
at org.elasticsearch.client.support.AbstractClient.bulk(AbstractClient.java:159)
at org.elasticsearch.client.transport.TransportClient.bulk(TransportClient.java:361)
at org.elasticsearch.action.bulk.BulkRequestBuilder.doExecute(BulkRequestBuilder.java:164)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:91)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:65)
at com.cisco.listprice.util.Utilities.deleteFromIndex(Utilities.java:414)
at com.cisco.listprice.thread.IndexDAO.processServiceCall(IndexDAO.java:156)
at com.cisco.listprice.thread.IndexDAO.loadAttributes(IndexDAO.java:66)
at com.cisco.listprice.thread.IndexDAO.execute(IndexDAO.java:443)
at com.cisco.listprice.thread.BaseThread.run(BaseThread.java:60)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
答案 2 :(得分:0)
我知道这是一篇旧帖子,但它引用了,所以这是我的解决方案:
只需用这样的自定义实现替换ScenarioContext:
public class ScenarioContextSafe
{
private static ScenarioContextSafe _current;
private static readonly object Locker = new object();
public static ScenarioContextSafe Current
{
get
{
lock (Locker) {
return _current ?? (_current = new ScenarioContextSafe());
}
}
}
public static void Reset()
{
lock (Locker) {
_current = null;
}
}
private readonly ConcurrentDictionary<string, object> _concurrentDictionary = new ConcurrentDictionary<string, object>();
public void Add(string key, object value)
{
_concurrentDictionary.TryAdd(key, value);
}
public void Set(object value, string key)
{
if (!_concurrentDictionary.ContainsKey(key))
_concurrentDictionary.TryAdd(key, value);
else
_concurrentDictionary[key] = value;
}
public void Remove(string key)
{
object result;
_concurrentDictionary.TryRemove(key, out result);
}
public T Get<T>(string key)
{
object result;
_concurrentDictionary.TryGetValue(key, out result);
return (T)result;
}
public bool ContainsKey(string key)
{
return _concurrentDictionary.ContainsKey(key);
}
public void Pending()
{
ScenarioContext.Current.Pending();
}
public ScenarioInfo ScenarioInfo{
get { return ScenarioContext.Current.ScenarioInfo; }
}
}
然后,在每个场景之前创建一个用于重置上下文的钩子
[BeforeScenario()]
public static void BeforeAllScenario()
{
ScenarioContextSafe.Reset();
}
我希望这有助于某人。