@@ -132,30 +132,25 @@ private[scalatest] object ConcurrentDocumenter {
132
132
//
133
133
private [scalatest] class MessageRecorder (dispatch : Reporter ) extends ThreadAwareness {
134
134
135
- private var messages = List [(String , Option [Any ], RecordedMessageEventFun , Option [Location ])]()
136
-
137
- // Should only be called by the thread that constructed this
138
- // ConcurrentInformer, because don't want to worry about synchronization here. Just send stuff from
139
- // other threads whenever they come in. So only call record after first checking isConstructingThread
140
- private def record (message : String , payload : Option [Any ], eventFun : RecordedMessageEventFun , location : Option [Location ]): Unit = {
141
- require(isConstructingThread)
142
- messages ::= (message, payload, eventFun, location)
143
- }
135
+ @ volatile private var messages = List [(String , Option [Any ], RecordedMessageEventFun , Option [Location ])]()
144
136
145
137
// Returns them in order recorded
146
- private def recordedMessages : List [(String , Option [Any ], RecordedMessageEventFun , Option [Location ])] = messages.reverse
138
+ private def recordedMessages : List [(String , Option [Any ], RecordedMessageEventFun , Option [Location ])] = synchronized {
139
+ messages.reverse
140
+ }
147
141
148
142
def apply (message : String , payload : Option [Any ], eventFun : RecordedMessageEventFun , location : Option [Location ]): Unit = {
149
143
requireNonNull(message, payload)
150
- if (isConstructingThread)
151
- record(message, payload, eventFun, location)
152
- else
153
- dispatch(eventFun(message, payload, false , false , false , location)) // Fire the info provided event using the passed function
144
+ synchronized {
145
+ messages ::= (message, payload, eventFun, location)
146
+ }
154
147
}
155
148
156
149
def recordedEvents (testWasPending : Boolean , testWasCanceled : Boolean ): collection.immutable.IndexedSeq [RecordableEvent ] = {
157
- Vector .empty ++ recordedMessages.map { case (message, payload, eventFun, location) =>
158
- eventFun(message, payload, true , testWasPending, testWasCanceled, location)
150
+ synchronized {
151
+ Vector .empty ++ recordedMessages.map { case (message, payload, eventFun, location) =>
152
+ eventFun(message, payload, true , testWasPending, testWasCanceled, location)
153
+ }
159
154
}
160
155
}
161
156
}
0 commit comments