I really have no idea then. Incidentally, a static class is typically not considered a Singleton. Here are some typical Singleton implementation patterns for C# and an analysis: http://www.yoda.arachsys.com/csharp/singleton.html
Note that if NUnit and MbUnit can cause this failure to occur then it could happen in other circumstances too. Jeff. On Sat, Nov 22, 2008 at 9:33 AM, Tomas Florian <[EMAIL PROTECTED]>wrote: > > Actually the code I sent is all there is. This is a new project and the > very first test failed like this. So the code I sent isn't a partial > listing - that's all there was. > > > > [EMAIL PROTECTED] wrote: > > MbUnit really does nothing special with any of your code including static > classes. > > > > You might want to check how you implemented that Singleton. Perhaps the > shared connection is being closed somewhere. > > -----Original Message----- > > From: Tomas Florian <[EMAIL PROTECTED]> > > Date: Friday, Nov 21, 2008 7:31 pm > > Subject: MbUnit Re: Weird database connection failure > > To: [EMAIL PROTECTED]: [email protected] > > > > > > Sorry about that, the code should say: > > > > Controller.Initialize("DSN=SentenceDB"); > > > > Now the good news, I found an interesting workaround when you mentioned > the static initializer. I took out all the "static" keywords from my > controller class and instantiated it inside the Test the plain old way: > Controller c = new Controller(); > > > > It works fine now! > > > > What I'm wondering now is why can't I use "static" classes like I tried. > I've been doing it for ages without any problem - it's basically a > singleton pattern. In this example, I used it because I know my application > will never ever need to instantiate more than one Controller class. > > > > Attaching the debugger was a good idea too. Here are more details > regarding the behavior: > > - When I run with debugger attached to Mbunit gui there is no exception > thrown > > - When I run without debugger the exception is thrown the first time > after the assembly reloads in mbUnit (second time run is ok, it keeps > working fine until I press Assemblies->Reload) > > > > I should probably repost this on the developer forum instead. It looks > like there is something different about the way mbUnit deals with static > classes. > > > > Thank you for your help. > > > > > > > > > > > > > > [EMAIL PROTECTED] wrote: > > The test is calling Controller.Initialize with no args but the code you > included only has a variant with 1 arg. > > > > > >> I wonder if you have some kind of static initializer in there that might > be causing trouble. > >> > > > > > >> Alternately, there might be some problem if there are other tests that > affect the same static variables but that might run in a different order > sometimes... > >> > > > > > >> Certainly weird. Have you tried running the test under the debugger? > >> > > -----Original Message----- > > From: ixnaum <[EMAIL PROTECTED]> > > Date: Friday, Nov 21, 2008 4:16 pm > > Subject: MbUnit Weird database connection failure > > To: "MbUnit.User" <[email protected]>Reply-To: > [email protected] > > > > > > Hello, > > > > > >> I came across a really strange problem. I have to say that I'm > >> > > relatively new to mbUnit so maybe I'm missing something obvious - but I > had to post this because I just don't get it. > > > > > >> I can sucessfully connect to ODBC database outside of MbUnit, but the > same code fails (throws Mysql connect exception) when run inside > >> > > MbUnit. What's even more strange is that if I rerun the same test > > with no code change the second time, there is no exception thrown. > > And that's not where the strangeness ends. If I comment "IList list = > Controller.ColumnList;" the test will always succeed with no MySQL > > exception. If you look at that piece of code, it does nothing related > with the database. It just returns an empty IList. The exception > > trace even says that it's not that line of code that's throwing the > > exception, it's the line above. That makes sense - but why in the > > heck does it work just fine when "IList list =" is commented out. > > Sorry if this post doesn't make sense ... the whole thing doesn't make > sense. > > > > > >> I should add that I had something similar happen to the same code when I > used NUnit on it. I changed to MbUnit partly because I thought > >> > > NUnit was messed up. Actually NUnit made a bit more sense, in NUnit, > the MySQL exception was thrown every single time during > > Controller.Initialize() ... none of this: it-works-on-a-second-try-if- > you-click-run-again > > > > > >> Here is my test code: > >> > > [Test] > > public void Test() > > { > > > > > >> Controller.Initialize(); > >> > > IList list = Controller.ColumnList; > > > > > >> //I know I don't have any assert code here, but I tried to > keep the test to a minimum since it's behaving strange > >> > > > > > >> } > >> > > > > > > Controller code: > > > > > >> public class Controller > >> > > { > > private static List<string> groupTaggedColumns = new > > List<string>(); > > private static OdbcConnection connection; > > > > > >> public static IList ColumnList > >> > > { > > get > > { > > return groupTaggedColumns; > > } > > } > > > > > >> public static void Initialize(string DSNstring) > >> > > { > > connection = new OdbcConnection(DSNstring); > > connection.Open(); > > } > > } > > > > > > Exception > > (BTW I'm not even connecting to localhost, my DSN is setup to connect to > another host - again works fine with that line commented out): > > > > > > Message: ERROR [HY000] [MySQL][ODBC 5.1 Driver]Can't connect to MySQL > server on 'localhost' (10061) > > ERROR [HY000] [MySQL][ODBC 5.1 Driver]Can't connect to MySQL server on > > 'localhost' (10061) > > > > > >> Type: System.Data.Odbc.OdbcException > >> > > Source: > > Errors: System.Data.Odbc.OdbcErrorCollection > > ErrorCode: -2146232009 > > TargetSite: Void HandleError(System.Data.Odbc.OdbcHandle, RetCode) > > HelpLink: null > > Stack: at System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle > > hrHandle, RetCode retcode) > > at System.Data.Odbc.OdbcConnectionHandle..ctor(OdbcConnection > > connection, OdbcConnectionString constr, OdbcEnvironmentHandle > > environmentHandle) > > at System.Data.Odbc.OdbcConnectionFactory.CreateConnection > > (DbConnectionOptions options, Object poolGroupProviderInfo, > > DbConnectionPool pool, DbConnection owningObject) > > at > > System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection > > (DbConnection owningConnection, DbConnectionPoolGroup poolGroup) > > at System.Data.ProviderBase.DbConnectionFactory.GetConnection > > (DbConnection owningConnection) > > at System.Data.ProviderBase.DbConnectionClosed.OpenConnection > > (DbConnection outerConnection, DbConnectionFactory connectionFactory) > > at System.Data.Odbc.OdbcConnection.Open() > > at StretchBase.Core.Controller.Initialize(String DSNstring) in > > xxxxxxxxxxxxxx > > at StretchBase.MbUnit.ColumnListTests.Test() in xxxxxxxxxxxx > > > > > > Please help - I'm out of ideas. > > Thank you! > > > > > > > > > > > > > > > > >> > >> > > > > > > > > > > > > > > > > > > > > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "MbUnit.User" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/MbUnitUser?hl=en -~----------~----~----~----~------~----~------~--~---
